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

lvguodong 2006-08-15 12:03:01
各位高手,我使用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中的这一条语句,这样我就不知道在哪一块申请的内存造成了内存泄露。

请教各位高手,我该如何解决这个问题,才能使我的内存泄露检测变得有意义?多谢了。
...全文
116 1 打赏 收藏 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
tidyduck 2006-08-16
  • 打赏
  • 举报
回复
http://www.vckbase.com/document/viewdoc/?id=1349
看看有帮助没?

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧