글
Programming 2009. 3. 10. 17:01Windows Programming에서 Memory leak 감지
뭐...사실 좋은 툴들 많지만. 그냥 Windows에서 자체 제공하는것으로 체크하는 방법.
#include <stdlib.h> // STEP 1
#include <crtdbg.h> // STEP 2
int main()
{
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
int * p = (int *)malloc(sizeof(int) * 10);
_CrtDumpMemoryLeaks( );
}
요렇게 종료전에 CrtDumpMemoryLeaks 호출하면 memory leak이 있을경우 알려준다.
(위에서는 STDOUT으로 설정했으니까 콘솔창에 보여진다)
#include <stdlib.h> // STEP 1
#include <crtdbg.h> // STEP 2
int main()
{
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
int * p = (int *)malloc(sizeof(int) * 10);
_CrtDumpMemoryLeaks( );
}
요렇게 종료전에 CrtDumpMemoryLeaks 호출하면 memory leak이 있을경우 알려준다.
(위에서는 STDOUT으로 설정했으니까 콘솔창에 보여진다)
RECENT COMMENT