Re: Singleton pattern and destruction

From: Ulrich Eckhardt (
Date: 02/05/04

Date: Thu, 05 Feb 2004 22:03:02 +0100

Erik J�evik wrote:
> However, the auto_ptr needs access to the singleton's destructor in
> order to call delete on it. But, since it's a singleton, I want the
> destructor to be protected so that no other class can call it.
> Any suggestions on how to to get around this?

Make auto_ptr<your_class> a friend?

There's other ways, too, using e.g. boost::shared_ptr<> with a custom
deleter or things like that.


Questions ?
see  C++-FAQ Lite:  first !

Relevant Pages

  • Re: Shared globals between two classes
    ... >> print function in foo.cpp and the implementation of the work function ... Singleton to do anything, but it has no state of its own. ... The reason you see no message from this destructor can be twofold. ... a.c.l.l.c-c++ FAQ mirror: ...
  • Re: mem leak in Singleton?
    ... Purify does not show it has mem leak. ... > class Singleton { ... > void print(); ... The destructor was never called. ...
  • RE: Singleton and garbage collection
    ... I have a singleton that tracks web activity on my web site. ... except that it restarts periodically. ... > instantiating the singleton but no destructor calls: ...
  • Re: Serializing an object from HttpApplicationState
    ... Suddenly I had the brilliant idea of creating a destructor for my object ... why didn't i thought about it before?), and applying a singleton ... pattern for it, so there is only one instance of it and when it is ...
  • Singleton problems
    ... I posted a question yesterday about a Singleton I have, ... my Singleton restarting happens at the same time as an application restart. ... Why wouldn't it's destructor ever be called? ...