tips

Windows開発環境下でのmemory leakチェック方法。

#include "stdafx.h"
#define _CRTDBG_MAP_ALLOC
#include 

int CALLBACK WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
                     LPSTR pCmdLine, int nCmdShow)
{
    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF |
                               _CRTDBG_LEAK_CHECK_DF);

     int* foo = NULL;
     foo = new int; // allocate memory

     return 0;
}

result...

Detected memory leaks!
Dumping objects ->
c:\program files\microsoft visual studio\vc98\include\crtdbg.h(552) : {42} normal block at 0x00371000, 4 bytes long.
 Data: <    > CD CD CD CD 
Object dump complete.

こういうことなんです。
{42}ってのが42番目に確保されたメモリであって、
確保した時にbreakかける事ができます。

int CALLBACK WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
                     LPSTR pCmdLine, int nCmdShow)
{
    _CrtSetBreakAlloc(42);
    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF |
                               _CRTDBG_LEAK_CHECK_DF);

     int* foo = NULL;
     foo = new int; // allocate memory

     return 0;
}

ってやるとさっきのメモリリークしてる場所で
break掛かります。
OK牧場