Re: Init Question
Re: Init Question
- Subject: Re: Init Question
- From: Jon Hull <email@hidden>
- Date: Sat, 25 Oct 2003 16:47:27 -0700
What is the proper behavior of an initialization method if it is
passed bad data?
It seems by example (NSArray's initWithContentsOfFile:) that I should
return nil which is fine, but how do I prevent a memory leak, since
alloc has already been called?
If an initializer method returns nil, then it has already released the
object. You don't have to care about releasing it yourself.
(An initializer can also substitute the alloc'ed object with another.
That's why you must absolutely reassign self to the value returned by
the initializer of the superclass in your own initializer.)
So if my initializer receives bad data, should it call [self dealloc]
and return nil?
Thanks,
Jon
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.