CheckLeak.h
#if defined(_DEBUG)
# include <crtdbg.h>
# if defined(malloc)
# undef malloc
# endif
# define malloc(s) (_malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__ ))
# if defined(calloc)
# undef calloc
# endif
# define calloc(c, s) (_calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__ ))
# if defined(realloc)
# undef realloc
# endif
# define realloc(p, s) (_realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__ ))
# if defined(_expand)
# undef _expand
# endif
# define _expand(p, s) (_expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__  ))
# if defined(free)
# undef free
# endif
# define free(p) (_free_dbg(p, _NORMAL_BLOCK))
# if defined(_msize)
# undef _msize
# endif
# define _msize(p) (_msize_dbg(p, _NORMAL_BLOCK))
# define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
class CheckMemoryLeakForWin32 {
public:
	CheckMemoryLeakForWin32() {
		_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
		// 중단점 트리거
		//_CrtSetBreakAlloc(2774);
	}
	~CheckMemoryLeakForWin32() {}
}CheckMemoryLeakForWin32;
#endif


Main.cpp
#include "CheckLeak.h"

int main(void)
{
	char* tmp = new char;
	return 0;
}​


Debug 실행시 (F5) - Output 창
'testConsole.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'
Detected memory leaks!
Dumping objects ->
c:\work\visualstudio\temp\testconsole\testconsole\main.cpp(5) : {124} client block at 0x00036550, subtype 0, 1 bytes long.
 Data: < > CD 
Object dump complete.
The program '[1968] testConsole.exe: Native' has exited with code 0 (0x0). ​

 
 
 

 

'C++' 카테고리의 다른 글

virtual 와 상속 속성  (0) 2010.11.10
stable priority queue  (0) 2010.11.08
log4cxx  (0) 2010.11.06
Singleton (싱글톤)  (0) 2010.11.05
Distributed Environment (분산 환경)  (0) 2010.11.04
ATL (Active Template Library)  (0) 2010.11.04
ActiveX control  (0) 2010.11.04
OLE (Object Linking and Embedding)  (0) 2010.11.04