• 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: Handling returning nil from init
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Handling returning nil from init


  • Subject: Re: Handling returning nil from init
  • From: j o a r <email@hidden>
  • Date: Tue, 12 Jul 2005 17:02:52 +0200


On 12 jul 2005, at 16.53, Theodore H. Smith wrote:

id obj = [[MyClass alloc]init];
if (obj) {
    [self DoStuffWith:obj];
}

OK, however, if obj is nil, we'll have leaked it, because we successfully alloced it.

It's the responsibility of the init method to release the object if it's going to return nil:


- (id) init
{
    if (nil != (self = [super init]))
    {
        if (<whatever you check>)
        {
            // Stuff...
        }
        else
        {
            [self release];
            self = nil;
        }
    }

    return self;
}

j o a r


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Handling returning nil from init (From: "Theodore H. Smith" <email@hidden>)

  • Prev by Date: Re: Handling returning nil from init
  • Next by Date: Drawing an NSImage into a GWorld
  • Previous by thread: Re: Handling returning nil from init
  • Next by thread: Drawing an NSImage into a GWorld
  • Index(es):
    • Date
    • Thread