This documentation is archived and is not being maintained.

Debug Heap Features

This topic applies to:


Visual Basic




Web Developer


Topic does not applyTopic does not applyTopic does not apply

Native only

Topic does not apply

Pro, Premium, and Ultimate

Topic does not applyTopic does not applyTopic does not apply

Native only

Topic does not apply

Many of the debug heap's features must be accessed from within your code. The following section describes some of the features and how to use them.


You can use a call to _CrtCheckMemory, for example, to check the heap's integrity at any point. This function inspects every memory block in the heap, verifies that the memory block header information is valid, and confirms that the buffers have not been modified.


You can control how the debug heap keeps track of allocations using an internal flag, _crtDbgFlag, which can be read and set using the _CrtSetDbgFlag function. By changing this flag, you can instruct the debug heap to check for memory leaks when the program exits and report any leaks that are detected. Similarly, you can specify that freed memory blocks not be removed from the linked list, to simulate low-memory situations. When the heap is checked, these freed blocks are inspected in their entirety to ensure that they have not been disturbed.

The _crtDbgFlag flag contains the following bit fields:

Bit field

Default value




Turns on debug allocation. When this bit is off, allocations remain chained together but their block type is _IGNORE_BLOCK.



Prevents memory from actually being freed, as for simulating low-memory conditions. When this bit is on, freed blocks are kept in the debug heap's linked list but are marked as _FREE_BLOCK and filled with a special byte value.



Causes _CrtCheckMemory to be called at every allocation and deallocation. This slows execution, but catches errors quickly.



Causes blocks marked as type _CRT_BLOCK to be included in leak-detection and state-difference operations. When this bit is off, the memory used internally by the run-time library is ignored during such operations.



Causes leak checking to be performed at program exit via a call to _CrtDumpMemoryLeaks. An error report is generated if the application has failed to free all the memory that it allocated.