Skip to Content.
Sympa Menu

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

patterns-discussion AT lists.siebelschool.illinois.edu

Subject: General talk about software patterns

List archive

Re: [patterns-discussion] deleting a Singleton


Chronological Thread 
  • From: "Eric Y. Theriault" <eric AT eyt.ca>
  • To: Peter Horan <peter AT deakin.edu.au>
  • Cc: patterns-discussion AT cs.uiuc.edu
  • Subject: Re: [patterns-discussion] deleting a Singleton
  • Date: Sat, 02 Oct 2004 01:10:01 -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

Peter Horan wrote:

Perhaps, logically, a singleton should not be destroyed, otherwise, it is possible to create a different instance of the singleton.


Yes, but does a Singleton pattern define the lifetime of the class? No, it only states that there will only be one instance of the class. There are several different types of Singletons, and while many Singletons have long lives, there are some particular needs for short lifetimes. I lack a clear example, but think of a Singleton that is used in a file parser or some genre of algorithm that is a small portion of the application; similar to how Design Patterns states in the Consequences that you can easily turn this pattern into a Multiton (multiple instances from a controlled entry point), the design pattern need not be interpreted as a single instance for the lifetime of the application (one instance for the entire application), but could also be interpreted as a single instance of an object at a given time (only one instance at any given time, but many instances over the application lifetime).

Furthermore, when an object's lifetime is the lifetime of the application's, it can still be important to release the resources that the Singleton holds, as previously mentioned on the forum.

Although the design pattern does not discuss the destruction of the object, this is as important as the pattern itself.



eyt*
--
Eric Y. Theriault
http://www.eyt.ca





Archive powered by MHonArc 2.6.16.

Top of Page