Re: Memory management on returning nil in init
Re: Memory management on returning nil in init
- Subject: Re: Memory management on returning nil in init
- From: Scott Anguish <email@hidden>
- Date: Mon, 21 Jun 2010 12:59:14 -0400
aside from what others have mentioned, one other comment
the new suggested format for calling super is
self = [super init];
if (self) {
etc...
On Jun 21, 2010, at 10:43 AM, Eiko Bleicher wrote:
> 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.
>
> Thanks,
> Eiko
>
> _______________________________________________
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
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:
This email sent to email@hidden