• 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: Best practice for overridden initializers in subclasses
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best practice for overridden initializers in subclasses


  • Subject: Re: Best practice for overridden initializers in subclasses
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 25 Mar 2008 17:09:34 -0700


On Mar 25, 2008, at 16:26, Andy Lee wrote:

A similar question was asked recently. To paraphrase (and slightly correct) my reply:

I do essentially this:

- (id)init
{
  NSLog(@"%@ -- '%@' is not the designated initializer",
        [self class],
        NSStringFromSelector(_cmd));
  [self release];
  return nil;
}

Unless there is some special runtime magic going on, this seems not absolutely safe. Your '[self release]' is going to eventually lead to a call of '[super dealloc]' and theoretically you can't safely call the superclass's dealloc if you haven't called a designated superclass initializer, because you don't know what the superclass's dealloc expects its initializer to have already done.


In practice, though, I can't imagine anything really bad happening -- all the dealloc has available to run amok with is a bunch of zeroes.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Best practice for overridden initializers in subclasses
      • From: Andy Lee <email@hidden>
    • Re: Best practice for overridden initializers in subclasses
      • From: Chris Suter <email@hidden>
References: 
 >Best practice for overridden initializers in subclasses (From: Andy Klepack <email@hidden>)
 >Re: Best practice for overridden initializers in subclasses (From: Andy Lee <email@hidden>)

  • Prev by Date: Re: Disabling NSTableView's text cell wrap-around tool tip?
  • Next by Date: Re: Garbage collection - was Beginner with Cocoa
  • Previous by thread: Re: Best practice for overridden initializers in subclasses
  • Next by thread: Re: Best practice for overridden initializers in subclasses
  • Index(es):
    • Date
    • Thread