• 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
Returning nil from -init
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Returning nil from -init


  • Subject: Returning nil from -init
  • From: Chris Ridd <email@hidden>
  • Date: Wed, 12 Mar 2003 09:18:41 +0000

I've got an init method that can fail if some of the input contains
incorrect data, and I understand the correct approach is to return nil in
this case. But it isn't clear to me what to do with the partial object
pointed at by self in this case. Is calling dealloc or release appropriate?

- (id)initWithData : (NSData *)pdb
{
if (self = [super init]) {
data = pdb;
[data retain];
if ([self parseData] == NO ) {
[self dealloc]; // or release?
self = nil;
}
}
return self;
}

My -dealloc method does a [data release], but I'm concerned that calling
-dealloc myself is bad style. Can I rely on -release doing the right thing?

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.

  • Follow-Ups:
    • Re: Returning nil from -init
      • From: Aram Greenman <email@hidden>
  • Prev by Date: Re: Anyone developing Database apps?
  • Next by Date: Re: Double property name in AppleScript problem
  • Previous by thread: Re: Toolbar hide/show button (Solved)
  • Next by thread: Re: Returning nil from -init
  • Index(es):
    • Date
    • Thread