Skip to content

Controlling Leak Detection at Runtime

Arkady Shapkin edited this page Mar 31, 2017 · 4 revisions

Using the default configuration, VLD's memory leak detection will be enabled during the entire run of your program. In certain scenarios, it may be desirable to selectively disable memory leak detection in certain segments of your code. VLD provides simple APIs for controlling the state of memory leak detection at runtime. To access these APIs, include vld.h in the source file that needs to use them.

VLDDisable This function disables memory leak detection. After calling this function, memory leak detection will remain disabled until it is explicitly re-enabled via a call to VLDEnable.

void VLDDisable (void);

Arguments: This function accepts no arguments.

Return Value: None (this function always succeeds).

Notes: This function controls memory leak detection on a per-thread basis. In other words, calling this function disables memory leak detection for only the thread that called the function. Memory leak detection will remain enabled for any other threads in the same process. This insulates the programmer from having to synchronize multiple threads that disable and enable memory leak detection. However, note also that this means that in order to disable memory leak detection process-wide, this function must be called from every thread in the process.

VLDEnable This function enables memory leak detection if it was previously disabled. After calling this function, memory leak detection will remain enabled unless it is explicitly disabled again via a call to VLDDisable().

void VLDEnable (void);

Arguments: This function accepts no arguments.

Return Value: None (this function always succeeds).

Notes: This function controls memory leak detection on a per-thread basis. See the remarks for VLDDisable regarding multithreading and memory leak detection for details. Those same concepts also apply to this function.