• 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: verify input parameter of init method and return nil before invoke [super init]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: verify input parameter of init method and return nil before invoke [super init]


  • Subject: Re: verify input parameter of init method and return nil before invoke [super init]
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 29 Jan 2013 09:07:08 -0800

On Jan 29, 2013, at 1:22 AM, Quincey Morris <email@hidden> wrote:

> ** Here's an example that will crash with an early return:
>
>   if (self) {
>       if (foo == nil)
>           return nil;
>       _foo = foo;
>       _bar = malloc (100);
>       .....
>   }
> …..
> - (void) dealloc {
>    free (_bar);
> }

Actually this is fine, because free(NULL) is legal. A better example would be a dealloc that calls CFRelease, because [for some reason] CFRelease does crash if passed NULL.

I would argue that the bug here is in the dealloc method. Dealloc methods should be written to run correctly if the init method was not called or had to back out partway through. (And this is, I think, one of the reasons why +alloc zeroes out the bytes of an object.)

—Jens
_______________________________________________

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: verify input parameter of init method and return nil before invoke [super init]
      • From: Quincey Morris <email@hidden>
References: 
 >verify input parameter of init method and return nil before invoke [super init] (From: Bob Cromwell <email@hidden>)
 >Re: verify input parameter of init method and return nil before invoke [super init] (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: NSDocument's Open File Panel unresponsive when opening large file from disc
  • Next by Date: Re: NSDocument's Open File Panel unresponsive when opening large file from disc
  • Previous by thread: Re: verify input parameter of init method and return nil before invoke [super init]
  • Next by thread: Re: verify input parameter of init method and return nil before invoke [super init]
  • Index(es):
    • Date
    • Thread