#ifdef _DEBUG
 #define _INC_MALLOC  // exclude standard memory alloc procedures
 #define _CRTDBG_MAP_ALLOC // include Microsoft memory leak detection procedures
 #include "crtdbg.h"
#endif

프로그램 진입점에서 최초에  

#ifdef _DEBUG
 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
#endif


발견된 메모리 누수지점에 브레이크포인트 걸기

Detected memory leaks!
Dumping objects ->
{60} normal block at 0x00324818, 4 bytes long.
Data: <,   > 2C 00 00 00
Object dump complete.

위와같이 누수가 발견되었다면 CrtSetBreakAlloc함수를 다음과 같이 호출

#ifdef _DEBUG
 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
 _CrtSetBreakAlloc(60); //또는 _crtBreakAlloc = 60;
#endif

visual studio를 사용한다면
1. F11로 디버깅을 시작
2. ALT+F9를 눌러서 중단점 창
3. 새로만들기>새데이터중단점에서 주소(0x00324818) 입력
4. 적당한 바이트(위의 경우는 4)를 입력

_CRTDBG_MAP_ALLOC를 선언하면 이렇게 파일명과 라인번호까지 알려준다던데 안되더라..

Detected memory leaks!
Dumping objects ->
D:\VisualC++\CodeGuru\MemoryLeak\MemoryLeak.cpp(67) : {60}
normal block at 0x00324818, 4 bytes long.
Data: <,   > 2C 00 00 00
Object dump complete.

원인이나 해결책 아시는 분은 댓글 부탁드립니다.

문제점: stl사용 시 실제로 누수되지 않았는데도 불구하고 무조건 누수발생 보고됨.

http://msdn.microsoft.com/en-us/library/x98tx3cf
http://msdn.microsoft.com/ko-kr/library/w2fhc9a3.aspx

'library > CRT' 카테고리의 다른 글

errno  (0) 2011.01.08
유니코드를 위한 함수  (0) 2011.01.08
시간과 날짜와 관련된 라이브러리 함수들  (0) 2010.12.15
문자열 함수들의 버퍼 체크 방법 차이  (0) 2010.11.24
코딩시 Unicode 관련 고려사항  (0) 2010.11.23
블로그 이미지

란마12

,