Destruction-Managed SingletonA Compound Pattern for Reliable Deallocation of Singletons

Destruction-Managed Singleton
A Compound Pattern for Reliable Deallocation of Singletons
Evgeniy Gabrilovich

Listing 4. Sample main program (main.cxx).


#include "dmanager.h"
#include "resource.h"

class DestroyObjects {
public:
  ~DestroyObjects()
  { DestructionManager::instance.destroy_objects(); }
};

void main(void) {
  DestroyObjects() destroyer;

  // ...
  Resource::instance().process();

  // The destructor of 'destroyer' is invoked automatically on exit 
  // from 'main()', commencing the controlled destruction of singletons.
}

About the Author

Evgeniy Gabrilovich is a Strategic Development Team Leader at Comverse Technology Inc. He holds an M.Sc. in Computer Science from the Technion-Israel Institute of Technology. He may be contacted at [email protected].