Share via


How to: Enable Memory Diagnostics

This topic applies to:

Edition

Visual Basic

C#

F#

C++

Web Developer

Express

Topic does not apply Topic does not apply Topic does not apply

Native only

Topic does not apply

Pro, Premium, and Ultimate

Topic does not apply Topic does not apply Topic does not apply

Native only

Topic does not apply

Before you can use the memory diagnostics facilities, you must enable diagnostic tracing.

To enable or disable memory diagnostics

  • Call the global function AfxEnableMemoryTracking to enable or disable the diagnostic memory allocator. Because memory diagnostics are on by default in the debug library, you will typically use this function to temporarily turn them off, which increases program execution speed and reduces diagnostic output.

To select specific memory diagnostic features with afxMemDF

  • If you want more precise control over the memory diagnostic features, you can selectively turn individual memory diagnostic features on and off by setting the value of the MFC global variable afxMemDF. This variable can have the following values as specified by the enumerated type afxMemDF.

    Value

    Meaning

    allocMemDF

    Turn on diagnostic memory allocator (default).

    delayFreeMemDF

    Delay freeing memory when calling delete or free until program exits. This will cause your program to allocate the maximum possible amount of memory.

    checkAlwaysMemDF

    Call AfxCheckMemory every time memory is allocated or freed.

    These values can be used in combination by performing a logical-OR operation, as shown here:

    afxMemDF = allocMemDF | delayFreeMemDF | checkAlwaysMemDF;
    

See Also

Other Resources

Memory Leak Detection in MFC