Re: Proper way to create a singleton without @synchronized ?
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