On Mon, 21 Jun 2010 16:43:46 +0200, Eiko Bleicher said: >One of my initializers can fail and thus it should return nil. Consider >the following example: > >-(id) initWithBool:(BOOL)ok >{ > if (self = [super init]) > { > if (!ok) { > return nil; // Point of interest > } > } > return self; >} > >Does this code leak? I am inclined to think I need to call [self >release] before returning nil, but I am yet to see a piece of example >code for this. Or is my approach stupid? :-) > >Running in no-GC environment here.
As others have said: yes, you leak. But the solution is not to call [self release], what you should do is call [super dealloc]. See here for a previous discussion of this topic: <http://lists.apple.com/archives/Objc-language/2008/Sep/msg00133.html> -- ____________________________________________________________ Sean McBride, B. Eng s...@rogue-research.com Rogue Research www.rogue-research.com Mac Software Developer Montréal, Québec, Canada _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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/archive%40mail-archive.com This email sent to arch...@mail-archive.com