• 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: Andy Lee <email@hidden>
  • Date: Mon, 28 Nov 2005 21:06:25 -0500

On Nov 28, 2005, at 6:51 PM, David Gimeno Gost wrote:

On 28 Nov 2005, at 22:20, Ondra Cada wrote:

Oh sigh...

Agreed. :-)

I haven't seen one of Ondra's sighs on the list for a while. Glad to see he's alive and well. :)


Cripes, what a long thread. I've lost track of who favors what, but FWIW, I'm for not mucking with the strong conventional semantics of +allocWithZone:. I'd go with the simple +sharedInstance implementation using a local static variable, as illustrated numerous times on this thread, and stick with normal retain/release rules throughout your application.

Put resource cleanup inside the object's -dealloc method, as you would for a non-singleton. Then if you want to explicitly force cleanup, you can send one last -release message in response to the app-will-end notification. I don't think this is so evil. It's an additional convention (the final -release, that is) rather than a special casing of an existing one.

If you really want to discourage instances other than the shared instance (and maybe "shared instance" is a better term than the overloaded "singleton" in this context), you could have +allocWithZone: and -init throw exceptions. I think this is more appropriate than trying to have them silently paper over the fact that they were called when they shouldn't be.

--Andy
_______________________________________________
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>)

  • Prev by Date: Re: Is Apple's singleton sample code correct?
  • Next by Date: Core Data Fetch request very poor performance ??!
  • 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