Visual Studio的Detected memory leaks! 检测

Visual Studio调试程序时,程序退出后出现内存泄漏:

Detected memory leaks!
Dumping objects ->
 {9554} normal block at 0x003CDCC0, 44 bytes long.
Data: < e n d > 20 C1 65 01 01 00 00 00 6E 00 00 00 9C CE 64 01
 {9553} normal block at 0x003CDB58, 8 bytes long.
 Data: < D e < > 44 BD 65 01 C0 DC 3C 00
{9552} normal block at 0x003CDC50, 48 bytes long.
 Data: < e > A0 95 65 01 01 00 00 00 19 00 00 00 19 00 00 00
 Object dump complete.

解决方法:

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

_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
 _CrtSetBreakAlloc(9554);   // 9554为上面内存泄漏的块号.
 _CrtSetBreakAlloc(9553);
 _CrtSetBreakAlloc(9552);

2. 然后debug运行,程序自动断点在"内存块9554"分配的位置:

你可能感兴趣的:(Visual Studio的Detected memory leaks! 检测)