RE: Returning nil from -init
RE: Returning nil from -init
- Subject: RE: Returning nil from -init
- From: "Mondragon, Ian" <email@hidden>
- Date: Wed, 12 Mar 2003 12:47:22 -0600
perhaps the following would put us all at ease?
--- snip ---
- initWithData:(NSData *)pdb
{
if ((self = [super init]))
{
if ([self _parse
Data:pdb])
{
[self set
Data:pdb];
return self;
}
}
[self release];
return nil;
}
--- snip ---
>
-----Original Message-----
>
From: Chris Ridd [SMTP:email@hidden]
>
Sent: Wednesday, March 12, 2003 11:35 AM
>
To: email@hidden
>
Subject: Re: Returning nil from -init
>
>
On 12/3/03 4:41 pm, Mondragon, Ian <email@hidden>
>
wrote:
>
>
> oops - too many BOOL's on the brain...
>
>
>
> // then you can verify the pdb argument before
>
> // setting it as an ivar & not have to deal with it
>
> - initWithData:(NSData *)pdb
>
> {
>
> if ((self = [super init]))
>
> {
>
> if ([self _parseData:pdb])
>
> {
>
> [self setData:pdb];
>
>
>
> return self;
>
> }
>
> }
>
>
>
> return nil;
>
> }
>
>
>
> sorry...
>
>
>
> - ian
>
>
>
Hm, but surely that leaks 'self' if _parseData fails; the partially inited
>
object pointed at by self will have a retainCount of 1 and there will be
>
no
>
references to it (unless the superclass has stashed a reference to it
>
somewhere.)
>
>
Cheers,
>
>
Chris
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.