Why is _CrtDumpMemoryLeaks reporting a memory leak here?

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:

enter image description here

+5
source share
1 answer

Have you turned on <crtdbg.h>?

Are you sure you are working in debug mode?

In non-debug mode - calls _CrtDumpMemoryLeaks()are deleted by the preprocessor, leaving onlyif(TRUE)

EDIT: , , , malloc - . . ?

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
0

All Articles