• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Init Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Init Question
      • From: "Ian P. Cardenas" <email@hidden>
References: 
 >Init Question (From: Jon Hull <email@hidden>)
 >Re: Init Question (From: Ambroise Confetti <email@hidden>)

  • Prev by Date: Re: Init Question
  • Next by Date: Re: XCode for Jaguar?
  • Previous by thread: Re: Init Question
  • Next by thread: Re: Init Question
  • Index(es):
    • Date
    • Thread