• 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: Chris Suter <email@hidden>
  • Date: Fri, 28 Sep 2007 16:05:16 +1000

If [super init] fails it should have done [self release] before returning nil.

Okay so somewhere along the chain up to NSObject, some class in the hierarchy is responsible for issuing [self release] within it's aborted init. But just theoretically if it does go all the way up to NSObject which fails its init, is it's alloced memory leaked? Not that it will ever happen...

It will only leak if there is a bug. If you return nil from an init method you are responsible for releasing the object. If -[NSObject init] could fail, it would have to release the object.


http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/instm/ NSObject/init

- Chris

_______________________________________________

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


References: 
 >Memory leak if alloc succeeds but init fails? (From: "R.L. Grigg" <email@hidden>)
 >Re: Memory leak if alloc succeeds but init fails? (From: Chris Suter <email@hidden>)
 >Re: Memory leak if alloc succeeds but init fails? (From: "R.L. Grigg" <email@hidden>)

  • Prev by Date: Re: Memory leak if alloc succeeds but init fails?
  • Next by Date: Re: Memory leak if alloc succeeds but init fails?
  • 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