• 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: David Gimeno Gost <email@hidden>
  • Date: Wed, 30 Nov 2005 01:15:35 +0100

On 29 Nov 2005, at 20:03, Andreas Mayer wrote:

AFAIK it's not only singletons where you can't depend on dealloc being called before the application quits.

Therefore it might be necessary to listen to the appropriate notifications to do your cleanup; singleton or not.

I know. I never meant otherwise. But when you get the notification you must call some method to do the clean up. What I'm saying is that, telling an object to release the resources it manages is semantically identical to destroying it in most cases (i.e. the existence of the object has no purpose after those resources have been released), so, instead of sending it a -doCleanUp message, I might as well send it a -release message.


This has several advantages. One of them is that the design of the application becomes less dependent on the development environment. You can use the same design pattern no matter what, you just must be aware of which development environments require you to tell explicitly the object that you no longer need it.

To be honest, I really don't understand this discussion. No matter which exact implementation you choose - if the singleton is used as such, each one works.

No, it doesn't, that's the whole point of the discussion. With the implementation suggested by Apple's sample code, sending the singleton a -release message to tell it that it's no longer needed does not work. See <http://www.cocoabuilder.com/archive/message/cocoa/2005/11/28/151235> for an example of why this could be a problem. And there are other nasty side effects too, such as that you must write the -init method to take into account the possibility that it gets invoked more than once for the same object.


Note that the sample code provided by Apple will likely be copied and used by many novices without really understanding its nasty side effects nor why are all those methods actually being overridden. I could understand the current situation if there was a trade-off that justified writing the singleton that way, but there is none.

Regards.

_______________________________________________
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: Andreas Mayer <email@hidden>
    • Re: Is Apple's singleton sample code correct?
      • From: Andy Lee <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>)
 >Re: Is Apple's singleton sample code correct? (From: Andreas Mayer <email@hidden>)

  • Prev by Date: NSButton draws unwanted white background on overlay window
  • Next by Date: Re: Extension of CoreData to third party databases.
  • 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