• 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: glenn andreas <email@hidden>
  • Date: Tue, 12 Jul 2005 10:02:05 -0500


On Jul 12, 2005, at 9:53 AM, Theodore H. Smith wrote:

Let's say I have a class which could return nil, from "init" on non- bug conditions, where the error was a missing-file error or user configuration error or that sort of thing.


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.

That's not how the idiom works. If there is a failure that causes init to return nil, the init method should dealloc itself as well, and thus there is no leak.



Glenn Andreas email@hidden <http://www.gandreas.com/> wicked fun! quadrium | build, mutate, evolve | images, textures, backgrounds, art

_______________________________________________
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: Handling returning nil from init
  • Next by Date: Re: Handling returning nil from init
  • Previous by thread: Handling returning nil from init
  • Next by thread: Re: Handling returning nil from init
  • Index(es):
    • Date
    • Thread