• 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: Jim Correia <email@hidden>
  • Date: Sat, 26 Nov 2005 12:09:38 -0500

On Nov 26, 2005, at 12:02 PM, Uli Kusterer wrote:

But isn't that dangerous? That would mean that calling alloc/init on such an object would repeatedly call init on the same object :-(

You'll have to ask the person who wrote the sample :-)

Yes, initializing an object twice is generally a bad idea. AppKit doesn't expect you to do that, and the result will range from leaks to incorrect behavior.

If you want to enforce singleton-ness, perhaps returning a replacement object from the designated initializer is a better idea. (Or perhaps not - there may be reasons not to do that which aren't obvious to me right now.)

Jim
_______________________________________________
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: j o a r <email@hidden>
    • Re: Is Apple's singleton sample code correct?
      • From: Uli Kusterer <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: Jim Correia <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Uli Kusterer <email@hidden>)

  • Prev by Date: [ANN] MKAMRollOverExtensions 0.2
  • Next by Date: Re: Is Apple's singleton sample code correct?
  • 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