• 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: Proper way to create a singleton without @synchronized ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper way to create a singleton without @synchronized ?


  • Subject: Re: Proper way to create a singleton without @synchronized ?
  • From: WT <email@hidden>
  • Date: Sun, 17 Apr 2011 02:18:33 -0300

Hi Dave, thanks for replying.

On Apr 17, 2011, at 12:18 AM, Dave DeLong wrote:

> There are a whole bunch of ways to make singletons.  Some are much more work than others...

The amount of work is of little concern for me in this case because the singleton class will become a template like its @synchronized version already is, so I only have to do the work once.

> //if we overrode -init, then you could run into issues if you ever tried to alloc/init a MySingleton multiple times

True.

> It's a lot shorter, because you don't have to worry about overriding all of the <NSObject> memory management methods.  As long as you correctly retain and release this object, it will never cease to exist.

The only reason why I have that particular implementation is that I've seen it done that way (but with @synchronized rather than dispatch_once()) in Apple's docs. Where exactly escapes me right now.

Thanks again.
WT

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Proper way to create a singleton without @synchronized ? (From: WT <email@hidden>)
 >Re: Proper way to create a singleton without @synchronized ? (From: Dave DeLong <email@hidden>)

  • Prev by Date: Re: A very customized window
  • Next by Date: Re: Proper way to create a singleton without @synchronized ?
  • Previous by thread: Re: Proper way to create a singleton without @synchronized ?
  • Next by thread: Re: Proper way to create a singleton without @synchronized ?
  • Index(es):
    • Date
    • Thread