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: Andreas Mayer <email@hidden>
- Date: Sun, 4 Dec 2005 04:08:51 +0100
Am 04.12.2005 um 03:06 Uhr schrieb Dirk Stegemann:
What is the sound and important technical reason for overriding
the reference counting methods in the case of a singleton ?
To prevent it's accidental deallocation, when no other objects
happen to be retaining it.
(...)
This is a general problem which applies to all kinds of objects,
be they singletons or non-singeltons,
(...)
Following the argumentation of the advocators of the "Overwrite the
-dealloc method to do nothing" approach, this problem doesn't apply
to the singleton objects,
Provided that there is no memory management error in the application,
the singleton will not be deallocated, since it basically retains
itself. The normal Cocoa memory management rules DO apply.
No overwrite of dealloc needed.
I agree with Dietmar that all those additional security measures are
*not* part of the singleton pattern and therefore should *not* be
part of the sample code.
It might be a good idea to add a paragraph about all the problems
that could arise and some of the solutions suggested in this
discussion. But they should definitely not be included in the basic
code that's supposed to explain the pattern and how it can be
realized in Cocoa.
Andreas
_______________________________________________
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