원본자료: 링크1, 링크2


요약


#include "stdafx.h"

#include <crtdbg.h> 


class CMemLeak

{

public:

CMemLeak()

{

_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_DELAY_FREE_MEM_DF);


// 메모리 누수 난곳 찾아주는 함수

// _CrtSetBreakAlloc(108);

// 

// 다음과 같이 오류가 났을 떄 {} 안에 있는 값을 _CrtSetBreakAlloc 인자로 넣어주면 됨

// Dumping objects ->

// {108} normal block at 0x000987E8, 4 bytes long.

// Data: <    > CD CD CD CD 

}

};

CMemLeak MemLeak;


int _tmain(int argc, _TCHAR* argv[])

{

// 전체 메모리를 검사해서 동적 메모리 할당이 깨지거나, 삭제된 포인터에 접근한 걸 확인, 중간 중간에 넣어주자

_ASSERTE( _CrtCheckMemory( ) );


return 0; 

}


+ Recent posts