autorelease pool comprehension
autorelease pool comprehension
- Subject: autorelease pool comprehension
- From: Apple Developer <email@hidden>
- Date: Wed, 30 Mar 2011 09:53:21 -0700
Reading about autorelease pools gave me the idea that I could reduce the memory footprint of my iPhone app. So, to aid in my understanding of autorelease pools, I created a pool in a small loop and released it at the end. Then, I ran the app in the debugger with a breakpoint at the top of the loop. At the first breakpoint, I started up Instruments to watch for memory allocations. As I single stepped through the loop, I could see instruments record 2 NSNumber objects. On the next pass, I saw 4 NSNumber objects, On the next pass, I saw 6 NSNUmber objects. This progression continued. When the loop finished, none of the NSNumber objects had been released. They were released, however, when the applications run loop finished. I would have expected to see no more then 2 NSNumber objects allocated at any time.
do {
if ( ( rc = sqlite3_step( statement ) ) == SQLITE_ROW ) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSNumber *date = [NSNumber numberWithDouble:sqlite3_column_double( statement, 0 )];
NSNumber *hours = [NSNumber numberWithDouble:sqlite3_column_double( statement, 1 )];
[list addObject:[NSArray arrayWithObjects:date, hours, nil]];
[pool release];
}
} while ( rc == SQLITE_ROW );
Why were the NSNumber objects not released when the pool was released? I made sure that the app had been rebuilt and that I was debugging the app with the autorelease pool code. Does the debugger have anything to do with it? Is there any way I can observe proper behavior? What am I doing wrong?
Paul_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden