If you call _CrtDumpMemoryLeaks()
at the end of the main function, the behavior is expected since mp_data
will be deleted after calling _CrtDumpMemoryLeaks()
.
You will need to call _CrtDumpMemoryLeaks()
after the last static object destructor has been called (or rather, in the last destructor after freeing memory) if you do not want to see these leaks (a rather difficult task, I would not try this).
A cleaner approach is to instead of all static objects in the heap (at the beginning of main
) select all your static objects and free them at the end of main
, and then you can call _CrtDumpMemoryLeaks()
and you will not see any memory leak.
FYI static objects with constructors and destructors are considered bad anyway, because the order in which they are constructed / desctructed is not deterministic, and because of this, static objects often introduce errors that cannot be easily debugged.
Change Andrewβs comment: You can try to disable automatic calling before _CrtDumpMemoryLeaks
by calling _ CrtSetDbgFlag to disable the _CRTDBG_LEAK_CHECK_DF
flag. If this works, you can add a static object that calls _CrtDumpMemoryLeaks()
in your destructor. To make sure this object is destroyed last, you can use the # pragma init_seg directive (compiler) .
There is no clue if this works ... other than that, all other solutions will most likely require you to change the ITK library (which should be possible, is it an open source library after ??).
source share