• 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: Is Apple's singleton sample code correct?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is Apple's singleton sample code correct?


  • Subject: Re: Is Apple's singleton sample code correct?
  • From: Shaun Wexler <email@hidden>
  • Date: Tue, 29 Nov 2005 10:30:10 -0800

On Nov 29, 2005, at 10:05 AM, David Gimeno Gost wrote:

Then, Uli Kusterer provided a much better implementation using a different approach: instead of overriding +allocWithZone: he chose to override the -init method to ensure that only the instance created by the +sharedInstance method is ever returned. What I like most about this approach is not that the code is more self- documenting, but that it completely eliminates another nasty side effect that I haven't mentioned in the above paragraphs and that any +allocWithZone:-based approach would have: the repeated -init call problem.

For reasons that escape me, knowledgeable people in this list has kept arguing with me that I shouldn't really be concerned at all with the nasty side effects of the current Apple's sample code implementation. No valid technical reason has been given to justify that the singleton's -dealloc method should be prevented from ever being called. Yet some people have gone as far as saying that the functionality that everyone would put there for any other object, should be put somewhere else for singletons, just because -dealloc has been prevented from ever being called for no apparent reason.

Please refer to the "hardcore" singleton base superclass I posted a few years ago:


 <http://www.cocoabuilder.com/archive/message/cocoa/2004/2/13/97027>

--
Shaun Wexler
MacFOH
http://www.macfoh.com


_______________________________________________ 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
  • Follow-Ups:
    • Re: Is Apple's singleton sample code correct?
      • From: David Gimeno Gost <email@hidden>
References: 
 >Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Shawn Erickson <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Uli Kusterer <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Uli Kusterer <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: mmalcolm crawford <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: mmalcolm crawford <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Christian Brunschen <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: glenn andreas <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Ondra Cada <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Andy Lee <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)

  • Prev by Date: Re: Subclassing NSMutableDictionary
  • Next by Date: Re: Subclassing NSMutableDictionary
  • Previous by thread: Re: Is Apple's singleton sample code correct?
  • Next by thread: Re: Is Apple's singleton sample code correct?
  • Index(es):
    • Date
    • Thread