# Memory Leak detection with singletons?

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

## Recommended Posts

Greetings! I have a singleton template to hold my input devices, graphic core and resource pool. The problem is, as soon as I leave my WinMain functions, my singletons get destruct BUT there fore I can NOT call _CrtDumpMemoryLeaks(). For Example: class MyApp { CMyResourcePool m_Pool; } WinMain(...) { MyApp app; app.Run(); _CrtDumpMemoryLeaks(); //problems } .. m_Pool gets destruct I have tried to set some flags to call my _CrtDumpMemoryLeaks automaticaly, but it also starts right after WinMain and before m_Pool gets destruct. I need some kind of control for that, because I can't really exactly tell if everything was disposed. I could redesign my engine with somekind of m_Pool::Destroy() but I don't want to right now, because I have a lot of classes allready implemented. I also checked Bounds Checker but I do not like it, because it reports memory leaks even on EMPTY Debug programs, or even in its test enviorment, one might run Notepad.exe and it will throw memory leaks. Any suggestions? Thank you in advance!

##### Share on other sites
You could explicitly destroy your singletons before calling _CrtDumpMemoryLeaks().

##### Share on other sites
You can also instruct the CRT leak tracer to produce a memory report after the whole of your program instead of when you call it. This allows you to take into account the part of the program executed after the last line of the main. Here is some code:

// Install the memory leak tracer. This will report after all has finished.int nDbgFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );nDbgFlag |= _CRTDBG_LEAK_CHECK_DF;_CrtSetDbgFlag( nDbgFlag );

Greetz,

Illco