Re: Exceptions and autorelease pools
Re: Exceptions and autorelease pools
- Subject: Re: Exceptions and autorelease pools
- From: Larry Campbell <email@hidden>
- Date: Tue, 06 Dec 2011 19:04:45 -0500
On Dec 6, 2011, at 4:02 PM, Greg Parker wrote:
> 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?
Instruments claims there are no leaks. However, the heap grows and grows (as reported by malloc_zone_statistics).
> 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.
It still shouldn't leak. Exceptions are not necessarily uncommon, and in a long-running program any leaks are bad.
> @autoreleasepool does not leak.
For portability reasons I cannot use Objective-C 2.0.
- lc
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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