Re: Cleanup inside a failed init method
Re: Cleanup inside a failed init method
- Subject: Re: Cleanup inside a failed init method
- From: Charles Steinman <email@hidden>
- Date: Sat, 6 Dec 2008 13:36:19 -0800 (PST)
----- Original Message ----
> From: Ken Tozier <email@hidden>
> To: Cocoa Developers <email@hidden>
> Sent: Saturday, December 6, 2008 1:07:00 PM
> Subject: Cleanup inside a failed init method
>
> Hi
>
> I'm writing my own socket class using a bunch of BSD functions and am a little
> unclear on exactly what I should be doing to insure everything is cleaned up if
> any of the low level functions fail. If I return nil from my init, does the
> system call my dealloc method to allow proper cleanup? Or do I have to do the
> cleanup before returning?
The system will only call dealloc if the object is released. Happily, the object should be released anyway if you plan to return nil since otherwise you'll leak a half-initialized object every time the method fails. So you should release self and return nil.
Cheers,
Chuck
_______________________________________________
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