Controlling the destruction order of Singleton objects

Evgeniy Gabrilovich · 1999

The Singleton pattern [1] is a solution to (some of) the drawbacks of using global variables. Among its advantages is that the instance is always created prior to being referenced (this effectively solves the problem of initialization order when several interdependent instances are involved). This article examines some of the existing Singleton realizations in C++ and their drawbacks, and presents a solution to the complement problem, namely, the destruction order of global instances. To this end, I propose to use a Destruction Manager, so that all the singleton objects register with it, specifying interdependencies between them. Following [2], the Destruction Manager is analyzed as a composite design pattern. An improved Singleton implementation The Singleton object creational pattern [1] is a superior implementation of the notion of global objects. Its major benefits are 1) limitation on the number of class instances that can be created; 2) instances are only created if actually ...

Read the paper · More papers on PaperTik