Re: Cleanup inside a failed init method
Re: Cleanup inside a failed init method
- Subject: Re: Cleanup inside a failed init method
- From: "Adam R. Maxwell" <email@hidden>
- Date: Sat, 06 Dec 2008 13:53:52 -0800
On Dec 6, 2008, at 1:36 PM, Charles Steinman wrote:
From: Ken Tozier <email@hidden>
To: Cocoa Developers <email@hidden>
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.
I used the [self release] pattern for a long time, but this thread
indicates that you should clean up in the initializer, then call
[super dealloc] directly:
http://lists.apple.com/archives/objc-language/2008//Sep/msg00133.html
--
Adam
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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