• 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: Gorazd Krosl <email@hidden>
  • Date: Fri, 28 Sep 2007 05:11:21 -0400 (EDT)

Hi Russ,
You are not required to do anything. If superclass'
initializer returns nil it means that there was an
error and the instance has been already released.
Similarly, if there is an error in your initializer,
you are expected to release the object and return nil.

Hope it helps,
Gorazd

----------------------------------------

Apple's Cocoa Memory Management Programming guide
shows this pattern
for init:

- (id)init {
     if ((self = [super init])) {// superclass may
return nil
         // your initialization code goes here
     }
     return self;
}

Newb question: In the case of
    id myObject = [[MyObject alloc]init];
what happens to the allocated memory if the [super
init] fails and
how do I handle it since I dont have a self to
release?

Thx
Russ



      Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail at http://mrd.mail.yahoo.com/try_beta?.intl=ca

_______________________________________________

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

  • Prev by Date: Re: 'kASAppleScriptSuite' undeclared
  • Next by Date: name that method!
  • 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