Re: Proper retain/release etiquette
Re: Proper retain/release etiquette
- Subject: Re: Proper retain/release etiquette
- From: Roarke Lynch <email@hidden>
- Date: Tue, 23 Jul 2002 11:09:06 -0400
On Tuesday, July 23, 2002, at 03:42 AM, Ondra Cada wrote
Well, since it is a very very common bug, I would explicitly add that
the pattern
// *WRONG*
id foo=[[Xyz alloc] init];
// other code here
[foo release];
is bound to leak as soon as the "other code" happens to raise.
Therefore, the proper pattern is
// *RIGHT*
id foo=[[[Xyz alloc] init] autorelease]; // or just [Xyz xyz], if
available
// other code here
or, if you have very hard reasons not to autorelease, you need to use
NS_DURING/NS_HANDLER/NS_ENDHANDLER.
What would make this leak? I was under the impression that autorelease
was basically a delayed release call.
Roarke Lynch
-------------------------------
email@hidden
_______________________________________________
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.