patterns-discussion AT lists.siebelschool.illinois.edu
Subject: General talk about software patterns
List archive
- From: "Eric Y. Theriault" <eric AT eyt.ca>
- To: "E. Segura" <esegura2002ar AT yahoo.com.ar>
- Cc: patterns-discussion AT cs.uiuc.edu
- Subject: Re: [patterns-discussion] deleting a Singleton
- Date: Fri, 24 Sep 2004 22:28:05 -0400
- List-archive: <http://mail.cs.uiuc.edu/pipermail/patterns-discussion>
- List-id: General talk about software patterns <patterns-discussion.cs.uiuc.edu>
- Organization: http://www.eyt.ca
E. Segura wrote:
When using the Singleton pattern...
Who should delete the _instance?
Should I ask for it and delete it myself?
( i.e. delete(myClass::getInstance()) ????? )
or the class should keep a "reference count" and other
classes should inform when the don't use the instance
reference anymore.
John Vlissides has written a great article on the topic, entitled "To Kill a Singleton", which I believe you can get at http://www.research.ibm.com/designpatterns/pubs/ph-jun96.txt . Andre Alexandrescu's Modern C++ Design book also has a good treatment of the topic, where he basically allows this to be specified by a policy. In other words, the users of the singleton object should be (more or less) oblivious to how it is constructed and destroyed.
I would avoid the delete mechanism above, since this assumes that the pointer is allocated by new. In actuality, the value returned by getInstance() is not necessarily allocated by new, as Alexandrescu refers to the Meyers Singleton, where the singleton object is a static variable.
The above two resources offer are excellent insight to this issue.
eyt*
--
Eric Y. Theriault
http://www.eyt.ca
- [patterns-discussion] Doubts regarding Strategy Pattern, souravm, 09/23/2004
- Re: [patterns-discussion] Doubts regarding Strategy Pattern, Ralph Johnson, 09/24/2004
- [patterns-discussion] deleting a Singleton, E. Segura, 09/24/2004
- Re: [patterns-discussion] deleting a Singleton, Eric Y. Theriault, 09/24/2004
- <Possible follow-up(s)>
- RE: [patterns-discussion] Doubts regarding Strategy Pattern, sayan.mukherjee, 09/23/2004
- RE: [patterns-discussion] Doubts regarding Strategy Pattern, Sriram Gopalan, 09/23/2004
Archive powered by MHonArc 2.6.16.