问题:
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.