首页 新闻 会员 周边

{833} normal block at 0x00441158,内存泄露

0
悬赏园豆:5 [已解决问题] 解决于 2013-06-20 17:21

{833} normal block at 0x00441158, 8 bytes long.
Data: << B D > 3C 9D 42 00 80 09 44 00

 

对于此类问题如何定位到问题出现的那一行,??

何合的主页 何合 | 初学一级 | 园豆:177
提问于:2012-11-30 16:20
< >
分享
最佳答案
0

头文件中包括:

#ifdef _DEBUG // 内存泄漏检测支持。
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <malloc.h>    // 解决 malloc.h 与 crtdbg.h 顺序导致的 Debug Assertion Failed, "Corrupted pointer passed to _freea" 。
#include <crtdbg.h>
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif  // _DEBUG

 

int main()

{

   _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );

// 其它代码。

_CrtDumpMemoryLeaks();

return 0;

}

通常会在输出窗口中会有更详细的信息,能够定位到代码行。

收获园豆:5
Launcher | 高人七级 |园豆:45045 | 2012-11-30 16:31

我使用的头文件

#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

然后在入口函数处包含了下面的代码

int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag( tmpFlag );

 

最后结果输出窗口就会出现

{833} normal block at 0x00441158, 8 bytes long.
Data: << B D > 3C 9D 42 00 80 09 44 00

这样的信息,但是没有具体位置的信息

何合 | 园豆:177 (初学一级) | 2012-12-03 16:26

@何合: 你能照着我的代码写么?

#ifdef _DEBUG // 内存泄漏检测支持。 #define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <malloc.h>    // 解决 malloc.h 与 crtdbg.h 顺序导致的 Debug Assertion Failed, "Corrupted pointer passed to _freea" 。 #include <crtdbg.h> #ifndef DBG_NEW #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ ) #define new DBG_NEW #endif #endif  // _DEBUG

 

int main()

{

   _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );

// 其它代码。

int* p = new int;

_CrtDumpMemoryLeaks();

return 0;

}

 

如果你有多个独立的 DLL,每个 DLL 都要添加。

Launcher | 园豆:45045 (高人七级) | 2012-12-03 16:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册