RE: Memory leak if alloc succeeds but init fails?
RE: Memory leak if alloc succeeds but init fails?
- Subject: RE: Memory leak if alloc succeeds but init fails?
- From: Jeff Laing <email@hidden>
- Date: Fri, 28 Sep 2007 16:09:57 +1000
> If [super init] fails it should have done [self release] before
> returning nil.
I have to say, I was surprised by this, but on thinking about it, of course
it makes sense.
However, then I read the online documentation to see if it was spelled out
and found:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/
NSObject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/init
which seems to contain two contradictory statements.
"Subclass implementations of this method should initialize and return the
new object. If it can't be initialized, they should release the object and
return nil."
...snip...
"Every class must guarantee that the init method either returns a fully
functional instance of the class or raises an exception."
It seems to me that these can't both be true. You can't both 'return nil'
and 'raise an exception'
_______________________________________________
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