vc内存泄漏定位

问题:

Detected memory leaks!

Dumping objects ->
{1142} normal block at 0x03C50A98, 32 bytes long.
 Data: < Oo` e  0R N   O> 11 4F 6F 60 F6 65 F4 95 30 52 86 4E 01 FF 11 4F 
{870} normal block at 0x00651C28, 88 bytes long.
 Data: <                > 0A 00 00 00 0A 00 00 00 00 00 00 00 CD CD CD CD 

Object dump complete.


方法1: add #define _CRTDBG_MAP_ALLOC in your stdafx.h file, and recompile whole solution.

#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#define _INC_MALLOC
#endif


The problem is it shows allocator code, not your allocation itself. Still not very usefull. Now tricky part. Double click

C:\Program Files\Microsoft Visual Studio 8\VC\include\crtdbg.h

line. Set a trap (F9/Debug->Toggle Breakpoint) right click on the red dot and select condition and type _Size==<your leak size in this case 68>. Next time you will debug, program will stop if there will be 68 bytes allocated, then you can select Debug->Windows->Call Stack and if you are lucky you will see your memory leak.


方法2:

在程序开始启动的地方(足够前的地方,只要在泄漏的内存分配的前面)使用代码:

_CrtSetBreakAlloc(1142); //1142为上面内存泄漏的块号,然后在stack窗口从上到下可定位内存泄漏代码

_CrtSetBreakAlloc(870);

快捷键:shift+F11


此方法大部分情况都好用,但无法用于泄漏点是变动的情况。


See also: _CrtSetDbgFlag and _CrtSetBreakAlloc MSDN reference.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值