• Advertisement
Sign in to follow this  

Loki::Singleton & _CrtDumpMemoryLeaks

This topic is 4796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm (still) playing with the Loki library, and have a quick question about the implementation of Singleton. My program looks something like this:
// Headers

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	{
// Lots of really exciting things happen in here!
	}

	_CrtDumpMemoryLeaks();

	return 0;
}

// In WindowManager.h:

class SingletonWindowManager
{
// Even more really exciting class details!
};

typedef Loki::SingletonHolder<SingletonWindowManager> WindowManager;

So - SingletonWindowManager gives the class functionality, and WindowManager is the openly available singleton class, created using the default SingletonHolder policies. This reports a memory leak from _CrtDumpMemoryLeaks. Question : is this because the Singleton implementation uses atexit to destroy it's allocated memory? Thanks, Jim.

Share this post


Link to post
Share on other sites
Advertisement
Yes. The atexit() handlers are run after main finishes executing. Step out of main into the CRT source code.

Try using _CrtSetDbgFlag(_CRT_DBG_LEAK_CHECK); instead.

Share this post


Link to post
Share on other sites
I'm not sure how far into the post main crt code you'll get, the debugger has to let go of the process before it is quit.

Cheers
Chris

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks very much,
Jim.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement