Mac OSX objective-c NSString memory leaking with ARC -


today i've tested around nsstrings. sadly have serious memory leak when run code (xcode instruments showing me that):

- (ibaction)start:(id)sender {     while (true)  // yes know infinity loop     {         nsstring *test = [[nsstring alloc] init];         test = [nsstring stringwithformat:@"llalalallalalallalalalalallalalllallalalallalal"];         test = nil;          // why leak memory ? think arc releasing automatically ?     } } 

here's screenshot of instruments:

enter image description here

could me please me understand why code leaking (arc on)?

the memory in autorelease pool, memory reclaimed when pool drained. when run loop cycles in tight loop run loop never chance pool needs explicitly drained.

in situation inside toe loop add autorelease pool:

@autoreleasepool {     code } 

in case:

while (true)  // yes know infinity loop {     @autoreleasepool {         nsstring *test = [[nsstring alloc]init];         test = [nsstring stringwithformat:@"llalalallalalallalalalalallalalllallalalallalal"];         test = nil;      } } 

btw stringwithformat no format codes nothing more create string same if defined literally:

test = @"llalalallalalallalalalalallalalllallalalallalal"; 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -