• 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: Thu, 1 Dec 2005 18:46:15 +0100

On 1 Dec 2005, at 06:40, Scott Anguish wrote:

MySingleton* herewegoagain = [MySingleton sharedInstance];
[herewegoagain release]; // <- Will -dealloc be invoked or not?


Incidentally, aside from this ongoing whatever it is about singletons, that code is incorrect.

If you don't alloc/init or retain it, you have no business releasing it.

Agreed. I didn't mean otherwise. I was just trying to illustrate that, for the purposes of this ("ongoing whatever it is about singletons" :-)) discussion, the only differences between Shaun Wexler's implementation and the one suggested by Apple's sample code were the -init problem and complexity.

BTW, sending [sharedInstance release] from within a singleton's class method, or [self release] from within a singleton's instance method, _might_ be correct (since sharedInstance was obtained through alloc/init).

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: Scott Anguish <email@hidden>
  • Prev by Date: Re: NSSearchField _sendPartialString exception
  • 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