A follow-up question to Memory leaks when calling ITK from Visual Studio DLL
I refined the problem to the simplest example.
struct A { public:
Any of following solves the problem.
(1) Create a fake dependency of the DLL on MFC, or
(2) Use the solution suggested by smerlin: add this code next to DllMain
struct _DEBUG_STATE { _DEBUG_STATE() {} ~_DEBUG_STATE() { _CrtDumpMemoryLeaks(); } }; #pragma init_seg(compiler) _DEBUG_STATE ds;