diff --git a/src/managers/settings.hpp b/src/managers/settings.hpp index 03d052502..598f113f6 100644 --- a/src/managers/settings.hpp +++ b/src/managers/settings.hpp @@ -8,8 +8,8 @@ #include -class GlobedSettings : public SingletonBase { - friend class SingletonBase; +class GlobedSettings : public SingletonLeakBase { + friend class SingletonLeakBase; GlobedSettings(); public: diff --git a/src/util/singleton.hpp b/src/util/singleton.hpp index fb2293d76..c98dbd377 100644 --- a/src/util/singleton.hpp +++ b/src/util/singleton.hpp @@ -35,3 +35,24 @@ class SingletonBase { destructed = true; } }; + +// This is like SingletonBase except not freed during program exit +template +class SingletonLeakBase { +public: + // no copy + SingletonLeakBase(const SingletonLeakBase&) = delete; + SingletonLeakBase& operator=(const SingletonLeakBase&) = delete; + // no move + SingletonLeakBase(SingletonLeakBase&&) = delete; + SingletonLeakBase& operator=(SingletonLeakBase&&) = delete; + + static Derived& get() { + static Derived* instance = new Derived(); + return *instance; + } + + +protected: + SingletonLeakBase() {} +};