• 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: Exceptions and autorelease pools
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Exceptions and autorelease pools


  • Subject: Re: Exceptions and autorelease pools
  • From: Greg Parker <email@hidden>
  • Date: Tue, 6 Dec 2011 13:02:49 -0800

On Dec 6, 2011, at 12:47 PM, Larry Campbell wrote:
> (Mac OS X 10.6.8, Xcode 4.0.2, no GC)
>
> I believe the following paragraph in the "Using Autorelease Pools" section of the "Memory Management Programming Guide" is wrong, or misleading:
>
> "This behavior has implications for exceptional conditions. If an exception occurs, and the thread suddenly transfers out of the current context, the pool associated with that context is drained. However, if that pool is not the top pool on the thread’s stack, all the pools above the drained pool are also drained (releasing all their objects in the process). The top autorelease pool on the thread’s stack then becomes the pool previously underneath the drained pool associated with the exceptional condition. Because of this behavior, exception handlers do not need to release objects that were sent autorelease. Neither is it necessary or even desirable for an exception handler to send release to its autorelease pool, unless the handler is re-raising the exception."
>
> In the following test program, if you leave the #define LEAK uncommented, the program leaks. Why? Is the above paragraph just wrong? Or am I missing something?

What does Instruments say the leaked objects are?

With NSAutoreleasePool, the autoreleased objects are handled correctly but the NSAutoreleasePool object itself leaks. In practice this is rarely noticed, because exceptions are uncommon and the NSAutoreleasePool object is small.

@autoreleasepool does not leak.


--
Greg Parker     email@hidden     Runtime Wrangler


_______________________________________________

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

  • Follow-Ups:
    • Re: Exceptions and autorelease pools
      • From: Larry Campbell <email@hidden>
References: 
 >Exceptions and autorelease pools (From: Larry Campbell <email@hidden>)

  • Prev by Date: Exceptions and autorelease pools
  • Next by Date: Web Kit - playing HTML5 video in a separate window
  • Previous by thread: Exceptions and autorelease pools
  • Next by thread: Re: Exceptions and autorelease pools
  • Index(es):
    • Date
    • Thread