【vs】内存泄露检测工具VisualLeakDetector

转自:https://blog.csdn.net/dalong277/article/details/52725778

转自:https://blog.csdn.net/winnyrain/article/details/51832850

转载与补充:

VisualLeakDetector下载地址:https://kinddragon.github.io/vld/

安装过程自动添加环境变量,自动关联VS并可以在新建的工程中默认添加了VisualLeakDetector头文件与库

安装完成后在VisualLeakDetector安装目录下找到vld.ini文件,修改

ReportTo = both

如果在后面测试的时候call stack没有输出信息,则修改

ReportEncoding = unicode

测试例程:

#ifdef _DEBUG
#include 
#endif // DEBUG
#include 
#include 
using namespace std;
int main(int argc, char** argv)
{
    char* vldPtr = new char;
    char* vldPtr2 = new char[100];
    Sleep(1000);
    //delete vldPtr;
    //delete[]vldPtr2;
    return 0;
}

调试运行,将会出现相应的内存泄露信息,双击发生内存泄露信息中的定位信息,会自动跳到发生内存泄露的语句,如下面的: 

Visual Leak Detector Version 2.5.1 installed.
    Generating a Unicode (UTF-16) encoded report.
    Outputting the report to the debugger and to C:\Users\machenike\Desktop\ConsoleApplication1\ConsoleApplication1\memory_leak_report.txt
线程 0x344c 已退出,返回值为 0 (0x0)。
线程 0x244c 已退出,返回值为 0 (0x0)。
线程 0x3fa4 已退出,返回值为 0 (0x0)。
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 2 at 0x007CA660: 100 bytes ----------
  Leak Hash: 0x16D4D026, Count: 1, Total 100 bytes
  Call Stack (TID 7552):
    MSVCR110D.dll!operator new()
    f:\dd\vctools\crt_bld\self_x86\crt\src\newaop.cpp (6): ConsoleApplication1.exe!operator new[]() + 0x9 bytes
    c:\users\machenike\desktop\consoleapplication1\consoleapplication1\源.cpp (10): ConsoleApplication1.exe!main() + 0x7 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (536): ConsoleApplication1.exe!__tmainCRTStartup() + 0x19 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (377): ConsoleApplication1.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xFD bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xCD bytes
  Data:
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ????????
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ????????
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ????????
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ????????
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ????????
    CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ????????
    CD CD CD CD                                                  ??......


---------- Block 1 at 0x007CA878: 1 bytes ----------
  Leak Hash: 0x8ABE9AD1, Count: 1, Total 1 bytes
  Call Stack (TID 7552):
    MSVCR110D.dll!operator new()
    c:\users\machenike\desktop\consoleapplication1\consoleapplication1\源.cpp (9): ConsoleApplication1.exe!main() + 0x7 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (536): ConsoleApplication1.exe!__tmainCRTStartup() + 0x19 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (377): ConsoleApplication1.exe!mainCRTStartup()
    KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xFD bytes
    ntdll.dll!RtlGetAppContainerNamedObjectPath() + 0xCD bytes
  Data:
    CD                                                           ........


Visual Leak Detector detected 2 memory leaks (173 bytes).
Largest number used: 173 bytes.
Total allocations: 173 bytes.
Visual Leak Detector is now exiting.


你可能感兴趣的:(c++,VS插件)