Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Immediate memory release




On 30 Apr '08, at 5:53 PM, Graham Cox wrote:

If <some code> throws an exception won't that mean that <pool> is leaked? (and all of its contents up to that point too; applies to both of our code examples).

Yup. You can work around that by using @finally:

for (i = 0; i < count; i++)
{
NSAutoreleasePool* pool = [NSAutoreleasePool new];
@try{
NSImage* tempSource = [[[NSImage alloc] initWithContentsOfFile:sPath[i]] autorelease];
// autorelease tempSource to ensure that we get cleaned up if anything in 'some code' throws an exception.
// pool will automagically be released later if an exception does happen and [pool release] get bypassed.


		// some code
	    }@finally{
	        [pool drain];
	    }
	}

I also changed the pool calls to the current recommended names: +new and -drain.

—Jens

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Immediate memory release (From: Yannick De Koninck <email@hidden>)
 >Re: Immediate memory release (From: Graham Cox <email@hidden>)
 >Re: Immediate memory release (From: "Paul Bailey" <email@hidden>)
 >Re: Immediate memory release (From: Yannick De Koninck <email@hidden>)
 >Re: Immediate memory release (From: Graham Cox <email@hidden>)
 >Re: Immediate memory release (From: email@hidden)
 >Re: Immediate memory release (From: Graham Cox <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.