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