On Dec 6, 2008, at 1:36 PM, Charles Steinman wrote:

From: Ken Tozier <[EMAIL PROTECTED]>
To: Cocoa Developers <cocoa-dev@lists.apple.com>


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 (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 [EMAIL PROTECTED]

Reply via email to