Considering the following Singleton class, I am not releasing memory in the destructor. But the instance of this class will remain the life-time of the program as most of the single-ton class do. Is it really matter to release the attribute’s memory other than best practices perception?
class Singleton
{
private:
Singleton() { pbyte1 = new BYTE[100]; }
~Singleton() {};
BYTE* pbyte1;
static SingletonInstance* pInstance;
public:
static Singleton* GetInstance()
{
if( pInstace ) return pInstance;
else
pInstance = new Singleton();
}
};
It does matter for debugging. If you run a tool for detecting memory leaks, the leaks caused by this singleton will pollute the output, making it harder to detect real memory leaks.