----- Original Message ----

> From: Ken Tozier <[EMAIL PROTECTED]>
> To: Cocoa Developers <cocoa-dev@lists.apple.com>
> 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 (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