Let's say I have 3 classes(A, B and C). Every class has an instance variable of the Singleton class and uses this instance variable in some functions of the class.
This class could look like this:
SingletonClass* mSingletonClass; // declared in header file mSingletonClass = SingletonClass::getInstance(); // called in constructor mSingletonClass->doSomething(); // called in function doSomething() mSingletonClass->doSomething1(); // called in function doSomething1() SingletonClass.h
class SingletonClass : public QObject { Q_OBJECT public: static SingletonClass* getInstance(); // some functions private: SingletonClass(); SingletonClass(SingletonClass const&); SingletonClass& operator=(SingletonClass const&); static SingletonClass* mInstance; }; SingletonClass.m
SingletonClass* SingletonClass::mInstance = 0; SingletonClass* SingletonClass::getInstance() { if (!mInstance) { mInstance = new SingletonClass(); } return mInstance; } SingletonClass::SingletonClass() : QObject() { } How am I supposed to delete the instance variables?
If I call delete mSingletonClass; on every deconstructor(A, B and C), the application crashes.
Is it "enough" if I just call delete mSingletonClass; once, for instance in Class A?
SingletonClassis written. Do you have the source code for it? If the singleton is a static object, you don't need to delete it because it will be deleted when the application shuts down.