My mixed-mode MFC application is creating false memory leaks because the CRT doesn't have time to shut down before the MFC dll is shut down.
I have a very simple little app that shows the problem:
#include <windows.h>
#include <iostream>
struct LongTimeToDestroy
{
~LongTimeToDestroy()
{
std::cout << "Will get called!" << std::endl;
Sleep(3000);
std::cout << "Won't get called!" << std::endl;
}
};
LongTimeToDestroy gJamsUpTheCRT;
int main()
{
}
Compile with cl.exe /clr test.cpp
. When run, you get:
Will get called!
The crux of the problem is: any static/global variables that were declared before gJamsUpTheCRT
will not be deallocated. For example, in my case the MFC CWinApp-derived class is not cleaned up.
Is this expected behaviour? I would like to allow my app to completely shut down.
Thanks,