内存泄漏检测VLD

https://kinddragon.github.io/vld/

安装完成后,会自动将其include目录添加到VS的附加安装目录,将其静态库目录(lib目录)添加到VS的附加库目录,无需手动添加include目录和lib目录。

  1. In at least one C/C++ source file from your program, include the vld.h header file. It should not matter which file you add the include statement to. It also should not matter in what order the header is included in relation to other headers. The only exception is stdafx.h (or any other precompiled header). A precompiled header, such as stdafx.h, must always be the first header included in a source file, so vld.h must be included after any precompiled headers.
  2. If your program contains one or more DLLs that you would also like to check for memory leaks, then also include vld.h in at least one source file from each DLL to be included in leak detection.
  3. Build the debug version of your program。

vld.ini配置文件默认位于安装目录下,可将该配置文件复制到当前程序exe目录下。

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()    //disable memory leak detection

VLDEnable()    //enable memory leak detection

原文地址:https://www.cnblogs.com/larry-xia/p/11813285.html