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.测试用文件  
 - #include "vld.h"
 
  
-  
 
  
- #include "iostream.h"
 
  
- #include "stdio.h"
 
  
- #include "stdlib.h"
 
  
- #include "string.h"
 
  
-  
 
  
- void Function1(char *p)
 
  
- {
 
  
-        char *pTmp = new char[255];
 
  
-        memset(pTmp, 0x0, 255);
 
  
-        strncpy(pTmp, p, 255);
 
  
-        //delete pTmp;
 
  
- }
 
  
-  
 
  
- int Function2(void)
 
  
- {
 
  
-        char acString[] = "this is test!";
 
  
-        Function1(acString);
 
  
-        return 1;
 
  
- }
 
  
-  
 
  
- void Function3(void)
 
  
- {
 
  
-        Function2();
 
  
- }
 
  
- int main(void)
 
  
- {
 
  
-        cout << "begin.............." << endl;
 
  
-  
 
  
-        Function3();
 
  
-        cout << "end................" << endl;
 
  
-        return 1;
 
  
- }
 
  
-  
 
  复制代码 
 |