Should Singleton objects that don\'t use instance/reference counters be considered memory leaks in C++?
Without a counter that calls for explicit deletion of the singlet
How are you creating the object?
If you're using a global variable or static variable, the destructor will be called, assuming the program exits normally.
For example, the program
#include
class Test
{
const char *msg;
public:
Test(const char *msg)
: msg(msg)
{}
~Test()
{
std::cout << "In destructor: " << msg << std::endl;
}
};
Test globalTest("GlobalTest");
int main(int, char *argv[])
{
static Test staticTest("StaticTest");
return 0;
}
Prints out
In destructor: StaticTest
In destructor: GlobalTest