• 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: 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

  • Follow-Ups:
    • Re: Memory leak if alloc succeeds but init fails?
      • From: Half Activist <email@hidden>
  • Prev by Date: Re: Memory leak if alloc succeeds but init fails?
  • Next by Date: '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