firemail

标题: 内存泄露检测工具 vld [打印本页]

作者: hechengjin    时间: 2016-4-22 19:34
标题: 内存泄露检测工具 vld
http://vld.codeplex.com/
在包含入口函数的.cpp文件中包含vld.h就可以了。下面以一个例子进行说明(源程序见附录):
1. 加入头文件:

2.      编译:

3.      在debug方式下运行:查看VC的输出信息:

内存泄露所在的位置



4.查看VC输出信息:
"WARNING: Visual Leak Detector detected meory leaks!"


5. 如果没有内存泄露,此输出的信息为:
      "No memory leaks detected"


五.        附录
1.测试用文件

  1. #include "vld.h"



  2. #include "iostream.h"

  3. #include "stdio.h"

  4. #include "stdlib.h"

  5. #include "string.h"



  6. void Function1(char *p)

  7. {

  8.        char *pTmp = new char[255];

  9.        memset(pTmp, 0x0, 255);

  10.        strncpy(pTmp, p, 255);

  11.        //delete pTmp;

  12. }



  13. int Function2(void)

  14. {

  15.        char acString[] = "this is test!";

  16.        Function1(acString);

  17.        return 1;

  18. }



  19. void Function3(void)

  20. {

  21.        Function2();

  22. }

  23. int main(void)

  24. {

  25.        cout << "begin.............." << endl;



  26.        Function3();

  27.        cout << "end................" << endl;

  28.        return 1;

  29. }

复制代码






欢迎光临 firemail (http://www.firemail.wang:8088/) Powered by Discuz! X3