When the main code calls Singleton::getInstance()->someMethod() for the first time, is the instance an instance twice?
Not. Calling the static Singleton member does not create an instance of Singleton , so the only instance of Singleton here is the one you create with new . And you create it only once, because once instance points to it, you never call new again.
However, you have one problem: you were unable to create a getInstance static member function. I assume this is a typo / surveillance, because otherwise your program will not even compile. In fact, the declaration is poorly formed even as a non-static member. In addition, the constructor must be private in order to apply the notion that only getInstance can create an instance of a type.
Will there be a memory leak?
Yes, and that is what Leak Detector reports. However, this is minimal: the problem is that nothing needs to be delete for the singleton instance before your program shuts down.
Honestly, I would not worry about that. This may be one of those rare cases where a leak is acceptable, mainly because more than a "leak", it is just a one-time refusal to allocate when the process ends.
However, if you completely get rid of the pointer, you can simultaneously avoid both problems, since one of the last actions of your program will be to destroy objects of static storage duration:
#include <iostream> class Singleton { public: ~Singleton() { std::cout << "destruction!\n"; } static Singleton& getInstance() { static Singleton instance; return instance; } void foo() { std::cout << "foo!\n"; } private: Singleton() { std::cout << "construction!\n"; } }; int main() { Singleton::getInstance().foo(); } // Output: // construction! // foo! // destruction!
Not even a pointer needed!
This has the added benefit that the whole function becomes inherently thread safe, at least with C ++ 11.