使用Visual Leak Detector库来检测CRT类型内存泄漏

时间:2022-01-15 16:03:54

要想使用VLD很简单,只要在代码前包含VLD.h,如下例:

#include "stdafx.h"
#include "vld.h"

int main(int argc, char* argv[])
{
 char* p=new char[100];
  *p='A';
  printf("Hello World!\n");
 return 0;
}

//记得添加VLD的include和lib目录到工程设定中。

Visual Leak Detector相关链接:

中文 http://www.cnblogs.com/shentao/archive/2011/10/07/2200525.html

英文 http://www.codeproject.com/KB/applications/visualleakdetector.aspx 

Known Bugs and Restrictions

已知的问题和限制

There are currently no known bugs in the latest release, but there are some known restrictions:

在最后的发行版本里暂时没有发现问题,但是有一些已知规则:

  • VLD does not detect COM leaks, out-of-process resource leaks, or any other types of memory leaks that are not associated with the CRT heap. In simpler terms, VLD only detects memory leaks that are the result of calls tonew or malloc. Keep in mind that VLD was created as an alternative to the built-in memory leak detector, which also only detects leaks fromnew andmalloc.
  • VLD不能检测COM的泄露,进程外资源的泄露,或者和CRT堆无关联的其他类别的泄露。简单的说,VLD只能检测调用newmalloc而导致的内存泄漏。记住VLD是作为一种内建的内存泄漏检测工具而被设计出来的,所以它只能检测来自于newmalloc的泄露。
  • VLD is not compatible with version 6.5 of the Debug Help Library (dbghelp.dll). The recommended version ofdbghelp.dll to use with VLD is 6.3. Version 6.3 is included in the VLD distribution.
  • VLD和Debug Help Library (dbghelp.dll)库的6.5版本不兼容。配合VLD一起使用的dbghelp.dll的推荐版本是6.3。6.3已经被包含在VLD的发行包里。
  • The pre-compiled libraries included in the VLD distribution may not be compatible with Visual Studio 2005. If you need to use VLD with Visual Studio 2005,building VLD from source in Visual Studio 2005 should create compatible libraries.
  • 预编译好的VLD发行包可能和Visual Studio 2005不兼容。如果你需要在Visual Studio 2005里使用VLD,请在Visual Studio 2005通过VLD的源代码编译来得到兼容的库。