Re: Is Apple's singleton sample code correct?
Re: Is Apple's singleton sample code correct?
- Subject: Re: Is Apple's singleton sample code correct?
- From: Shaun Wexler <email@hidden>
- Date: Wed, 30 Nov 2005 20:30:12 -0800
On Nov 30, 2005, at 8:14 PM, David Gimeno Gost wrote:
Sorry for being so dense, but I think I still don't get it:
MySingleton* herewegoagain = [MySingleton sharedInstance];
[herewegoagain release]; // <- Will -dealloc be invoked or not?
No, it will not be dealloc'ed. Once a "hardcore" singleton is
created, it persists until the app quits.
What exactly differentiates your implementation from the one
suggested by Apple's sample code, apart from solving the -init
problem (at the cost of a much, much greater complexity)?
Mine is a thread-safe base class that can be used for nearly all
types of singleton subclasses, and is immune to most programming
errors (alloc+init, re-init, retain/release/copy/etc). My base
object class (SKWObject) provides fine-grained r/w locking, local ref
count, cacheline-alignment, and implements an efficient non-retained
bindings layer and automatic notification. SKWSingletonObject is a
subclass of SKWObject. The beauty of an object-oriented class
hierarchy is that any underlying complexity doesn't clutter the
higher-level subclasses.
--
Shaun Wexler
MacFOH
http://www.macfoh.com
"Any sufficiently advanced technology is indistinguishable from
magic." - Arthur C. Clarke
_______________________________________________
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