CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  工具平台和程序库

请教,利用VC检测内存泄露的问题

楼主lvguodong()2006-08-15 12:02:33 在 C/C++ / 工具平台和程序库 提问

各位高手,我使用VC6.0做了一个控制台工程,里面包含C、C++两种语言,为了检测内存泄露,在一个总的头文件中添加了如下代码:  
   
  #ifdef   _DEBUG  
  #define   _CRTDBG_MAP_ALLOC    
  #include<stdlib.h>    
  #include<crtdbg.h>  
  #endif  
   
  在程序的退出点添加了如下代码:  
   
  #ifdef   _DEBUG  
  _CrtDumpMemoryLeaks();  
  #endif  
   
  当我运行Debug模式并退出程序时,有如下输出:  
   
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324230}   normal   block   at   0x011100B0,   33   bytes   long.  
    Data:   <   1                             >   00   31   00   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324228}   normal   block   at   0x031E7768,   33   bytes   long.  
    Data:   <   0                             >   00   30   00   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324176}   normal   block   at   0x03095058,   33   bytes   long.  
    Data:   <   identify_text     >   00   69   64   65   6E   74   69   66   79   5F   74   65   78   74   00   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324175}   normal   block   at   0x033C5250,   116   bytes   long.  
    Data:   <     Q           ~               >   F0   ED   51   00   00   00   00   00   7E   00   00   00   00   00   00   00    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324174}   normal   block   at   0x030950C0,   33   bytes   long.  
    Data:   <   1                             >   00   31   00   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324173}   normal   block   at   0x030953B8,   60   bytes   long.  
    Data:   <4|Q           r               >   34   7C   51   00   00   00   00   00   72   00   00   00   00   00   00   00    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324171}   normal   block   at   0x03092508,   33   bytes   long.  
    Data:   <   sence_id               >   00   73   65   6E   63   65   5F   69   64   00   CD   CD   CD   CD   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324170}   normal   block   at   0x03093EA0,   116   bytes   long.  
    Data:   <     Q           h               >   F0   ED   51   00   00   00   00   00   68   00   00   00   00   00   00   00    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324169}   normal   block   at   0x03092570,   33   bytes   long.  
    Data:   <   0                             >   00   30   00   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324168}   normal   block   at   0x031A8ED0,   60   bytes   long.  
    Data:   <4|Q           \               >   34   7C   51   00   00   00   00   00   5C   00   00   00   00   00   00   00    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324166}   normal   block   at   0x030B93E0,   33   bytes   long.  
    Data:   <   flash_id               >   00   66   6C   61   73   68   5F   69   64   00   CD   CD   CD   CD   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324165}   normal   block   at   0x030910C8,   116   bytes   long.  
    Data:   <     Q           R               >   F0   ED   51   00   00   00   00   00   52   00   00   00   00   00   00   00    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324164}   normal   block   at   0x030B9448,   33   bytes   long.  
    Data:   <   0                             >   00   30   00   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324163}   normal   block   at   0x030920D0,   60   bytes   long.  
    Data:   <4|Q           D               >   34   7C   51   00   00   00   00   00   44   00   00   00   00   00   00   00    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324161}   normal   block   at   0x0316B648,   33   bytes   long.  
    Data:   <   contr_type           >   00   63   6F   6E   74   72   5F   74   79   70   65   00   CD   CD   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324160}   normal   block   at   0x034BE408,   116   bytes   long.  
    Data:   <     Q           8               >   F0   ED   51   00   00   00   00   00   38   00   00   00   00   00   00   00    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324158}   normal   block   at   0x0316EC98,   33   bytes   long.  
    Data:   <   identify_msg       >   00   69   64   65   6E   74   69   66   79   5F   6D   73   67   00   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324157}   normal   block   at   0x0323A280,   116   bytes   long.  
    Data:   <     Q           *               >   F0   ED   51   00   00   00   00   00   2A   00   00   00   00   00   00   00    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324156}   normal   block   at   0x0316EC30,   33   bytes   long.  
    Data:   <   SHIFT-JIS             >   00   53   48   49   46   54   2D   4A   49   53   00   CD   CD   CD   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324153}   normal   block   at   0x0316BF50,   33   bytes   long.  
    Data:   <   1.0                         >   00   31   2E   30   00   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD   CD    
  f:\program   files\microsoft   visual   studio\vc98\include\crtdbg.h(552)   :   {324150}   normal   block   at   0x0310B240,   104   bytes   long.  
    Data:   <D   Q                           >   44   EF   51   00   00   00   00   00   00   00   00   00   00   00   00   00    
  。。。。。。。。。。  
   
  这个报告指明产生内存泄露问题的内存申请点是:(在crtdbg.h文件中)  
   
  #ifdef   _CRTDBG_MAP_ALLOC  
   
  inline   void*   __cdecl   operator   new(unsigned   int   s)  
                  {   return   ::operator   new(s,   _NORMAL_BLOCK,   __FILE__,   __LINE__);   }  
   
  #endif     /*   _CRTDBG_MAP_ALLOC   */  
   
  我本来是要定位自己的源代码文件中产生内存泄露问题的内存申请点的,结果全指向了crtdbg.h中的这一条语句,这样我就不知道在哪一块申请的内存造成了内存泄露。  
   
  请教各位高手,我该如何解决这个问题,才能使我的内存泄露检测变得有意义?多谢了。  
  问题点数:0、回复次数:3Top

1 楼awjx(啦啦啦)回复于 2006-08-15 18:28:53 得分 0

我也想知道...Top

2 楼060(060)回复于 2006-09-17 12:57:09 得分 0

使用   new   申请内存,   我也遇到这个问题.  
  好像使用   malloc   申请内存,   大约能够定位到正确的地方.  
   
  使用   MFC   的内存检测,   好像没这个问题  
  http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vsdebug/html/_core_detecting_memory_leaks.aspTop

3 楼mumutouv(keke)回复于 2006-11-01 13:24:14 得分 0

使用boundschecker第三方Top

相关问题

关键词

得分解答快速导航

  • 帖主:lvguodong

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo