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: "Lachlan O'Dea" <email@hidden>
- Date: Mon, 11 Feb 2002 16:20:55 +1100
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.