I want to check for memory leak in DEBUG mode. I use Windows and for this work performs the function _ CrtDumpMemoryLeaks .
Now, why does this code detect a memory leak?
#include <Windows.h>
#include <iostream>
int main()
{
if(_CrtDumpMemoryLeaks() == TRUE)
std::cerr << "MEMORY LEAK!" << std::endl;
return 0;
}
EDIT:
I am adding this code for direct output to the console:
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
Conclusion:

source
share