I've used a singleton derived pattern for me (that support polymorphism i think, not tried), because i need a perfect control on what i singlelise :
Obj singleton;
SharedInstance(singleton);
SharedInstance<Obj>()->DoThat();
Obj singletwo;
SharedInstance(singletwo);
...
I agree with Groogy. although it's a C-like behavior, you need external memory management, because devs could need it and could be stopped by this leak.
But i don't manage it itself, I prefer let the user destroy it, or use a GTK-like Garbage, but with more semantics :
template<typename T>
class Garbage
{
public:
virtual ~Garbage();
T& Manage(T*); // I use reference, because the other code use reference, not a Qt like system
private:
std::vector<T*> m_Objects;
};
class GuiHandle : public Garbage<Widget> // GuiHandle can manage memory destruction for widgets object
{
};
I hope you understand me :oops: