• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: autorelease pool comprehension
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: autorelease pool comprehension


  • Subject: Re: autorelease pool comprehension
  • From: Paul Scott <email@hidden>
  • Date: Wed, 30 Mar 2011 10:10:58 -0700

Oh, man! That was some wicked beer I drank. I see now that I've retained those objects by adding them to the array.

Please ignore my questions.

Paul

On Mar 30, 2011, at 9:53 AM, Apple Developer wrote:

> 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

_______________________________________________

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

  • Prev by Date: Re: autorelease pool comprehension
  • Next by Date: Re: why I got wrong arguments from command-line
  • Previous by thread: Re: autorelease pool comprehension
  • Next by thread: Xcode 4.0 Application builds
  • Index(es):
    • Date
    • Thread