Skip to Content.
Sympa Menu

patterns-discussion - RE : [patterns-discussion] delet ing a Singleton

patterns-discussion AT lists.cs.illinois.edu

Subject: General talk about software patterns

List archive

RE : [patterns-discussion] delet ing a Singleton


Chronological Thread 
  • From: "Christophe Addinquy" <Christophe.Addinquy AT valtech.fr>
  • To: "Eric Y. Theriault" <eric AT eyt.ca>, "E. Segura" <esegura2002ar AT yahoo.com.ar>
  • Cc: patterns-discussion AT cs.uiuc.edu
  • Subject: RE : [patterns-discussion] delet ing a Singleton
  • Date: Mon, 27 Sep 2004 09:55:23 +0200
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/patterns-discussion>
  • List-id: General talk about software patterns <patterns-discussion.cs.uiuc.edu>

As far as I remember, John Vlissides material was first published in C++
Report, then synthitized in the excellent book "Patterns Hatching". I don't
know if the material is more or less complete, but the advantage of Eric's
link is the instant access..

Regards,


Christophe

-------- Message d'origine--------
De:
patterns-discussion-bounces AT cs.uiuc.edu
de la part de Eric Y. Theriault
Date: sam. 25/09/2004 04:28
À: E. Segura
Cc:
patterns-discussion AT cs.uiuc.edu

Objet: Re: [patterns-discussion] deleting a Singleton



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 mailing list

patterns-discussion AT cs.uiuc.edu
http://mail.cs.uiuc.edu/mailman/listinfo/patterns-discussion






  • RE : [patterns-discussion] delet ing a Singleton, Christophe Addinquy, 09/27/2004

Archive powered by MHonArc 2.6.16.

Top of Page