• 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: Memory leak if alloc succeeds but init fails?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory leak if alloc succeeds but init fails?


  • Subject: Re: Memory leak if alloc succeeds but init fails?
  • From: Half Activist <email@hidden>
  • Date: Fri, 28 Sep 2007 08:29:49 +0200

On a syntactic point of view, 'nil' can be seen as a fully functional object, it can be distinguished from other instances easily.
I suppose they meant that if the program wouldn't be able to tell a fully functional instance of a class from a non functional one, that is
what the initialization returns cannot be interpreted as a failure or a success from its result, then the initialization methods
must raise an exception to tell that something wrong happened.


Still, this would be really weird to proceed this way in an init method. :-\

On Sep 28, 2007, at 8:09 AM, Jeff Laing wrote:

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


  • Follow-Ups:
    • Re: Memory leak if alloc succeeds but init fails?
      • From: Wincent Colaiuta <email@hidden>
References: 
 >RE: Memory leak if alloc succeeds but init fails? (From: Jeff Laing <email@hidden>)

  • Prev by Date: 'kASAppleScriptSuite' undeclared
  • Next by Date: Re: 'kASAppleScriptSuite' undeclared
  • Previous by thread: RE: Memory leak if alloc succeeds but init fails?
  • Next by thread: Re: Memory leak if alloc succeeds but init fails?
  • Index(es):
    • Date
    • Thread