Singleton crash when application exit

Here is my singleton testing code:

class TestSingle {
public :
virtual ~TestSingle(){};
ValueTree abc{ “test” };
void test(){ …};


so in my maincode:


run is ok,and when close window ,it shows leak of object count;

Taking a look at the docs should help:

As the example there shows, you need to call deleteInstance on your singleton at shutdown.

greate thanks. now I am using sharedobjectpointer instead of singleton to be more safe bettween windows.

You can inherit your Singleton from DeletedAtShutdown, which will take care of deleting without leaking (like the name suggests).

The difference to SharedResourcePointer is, that the SharedResourcePointer is created on the fly and deleted as soon as possible, vs. the singleton stays alive until the application shuts down or it is deleted manually.

1 Like

that’s ok… I use shareresourcepointer fine now. as I will load global vars in the main,and main will never exist before other window/modules.