_CrtDumpMemoryLeaks

Dumps all the memory blocks in the debug heap when a memory leak has occurred (debug version only).

Syntax


int _CrtDumpMemoryLeaks( void );

Return value

_CrtDumpMemoryLeaks returns TRUE if a memory leak is found. Otherwise, the function returns FALSE.

Remarks

The _CrtDumpMemoryLeaks function determines whether a memory leak has occurred since the start of program execution. When a leak is found, the debug header information for all the objects in the heap is dumped in a user-readable form. When _DEBUG isn't defined, calls to _CrtDumpMemoryLeaks are removed during preprocessing.

_CrtDumpMemoryLeaks is frequently called at the end of program execution to verify that all memory allocated by the application has been freed. The function can be called automatically at program termination by turning on the _CRTDBG_LEAK_CHECK_DF bit field of the _crtDbgFlag flag using the _CrtSetDbgFlag function.

_CrtDumpMemoryLeaks calls _CrtMemCheckpoint to obtain the current state of the heap and then scans the state for blocks that haven't been freed. When an unfreed block is encountered, _CrtDumpMemoryLeaks calls _CrtMemDumpAllObjectsSince to dump information for all the objects allocated in the heap from the start of program execution.

By default, internal C run-time blocks (_CRT_BLOCK) aren't included in memory dump operations. The _CrtSetDbgFlag function can be used to turn on the _CRTDBG_CHECK_CRT_DF bit of _crtDbgFlag to include these blocks in the leak detection process.

For more information about heap state functions and the _CrtMemState structure, see Heap state reporting functions. For more information about how memory blocks are allocated, initialized, and managed in the debug version of the base heap, see CRT debug heap details.

Requirements

Routine Required header
_CrtDumpMemoryLeaks <crtdbg.h>

For more compatibility information, see Compatibility.

Libraries

Debug versions of C run-time libraries only.

Example

For a sample of how to use _CrtDumpMemoryLeaks, see crt_dbg1.

See also

Debug routines