Re: Handling returning nil from init
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