Re: newbie question on 'Cocoa Programming for Mac OS X'
Re: newbie question on 'Cocoa Programming for Mac OS X'
- Subject: Re: newbie question on 'Cocoa Programming for Mac OS X'
- From: "Erik M. Buck" <email@hidden>
- Date: Mon, 11 Feb 2002 08:49:56 -0600
- Organization: EMB & Assocites Inc.
Autorelease pools are always nested and will be released when their parent
pool is released.
----- Original Message -----
From: "Lachlan O'Dea" <email@hidden>
To: <email@hidden>
Sent: Sunday, February 10, 2002 11:20 PM
Subject: Re: newbie question on 'Cocoa Programming for Mac OS X'
>
At 16:53 +0100 09/02/2002, Ondra Cada wrote:
>
>So far as I see, just one: the buggy pattern is
>
>
>
>RC> NSMutableArray *tempArray=[[NSMutableArray alloc]init];
>
>RC> ... work done here ...
>
>RC> [tempArray release];
>
>
>
>since if "work" happened to raise an exception, tempArray would leak. The
>
>proper pattern is
>
>
>
>NSMutableArray *tempArray=[NSMutableArray array];
>
>... work done here ...
>
>
>
>(and it is even nicer and more convenient).
>
>
>
>In those *extremely rare* cases when the autorelease pool might
compromise
>
>effectivity, the primary solution is
>
>
>
>NSAutoreleasePool *localPool=[[NSAutoreleasePool alloc] init];
>
>NSMutableArray *tempArray=[NSMutableArray array];
>
>... work done here ...
>
>[localPool release];
>
>
Isn't this still a problem if an exception is raised? [localPool
>
release] would not be executed in that case.
>
>
--
>
Lachlan O'Dea <email@hidden> Computer Associates Pty Ltd
>
Webmaster Vet - Anti-Virus Software
>
http://www.vet.com.au/
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.