반응형

블로그 이미지

3DMP engines

3D그래픽스 물리 수학, 프로그래밍 GPU Shader 게임엔진 알고리즘 디자인패턴 matlab etc..

by 송정헌





#include <vld.h>  를 써서 헤더선언



download



http://aiesko.blog.me/20139603723

비주얼 스튜디오에서 개발하면서 메모리 누수에 대한 경고는 보기 힘듭니다.

 

그래서 저는 이 플러그인을 이용하여 프로젝트에서 메모리 누수를 확인합니다.

 

첨부한 압축 파일을 압축 해제하면 여러 파일들이 나오는데 간단한 경로에 파일들을 모아놓습니다.

 

그리고 개발하고 있는 프로젝트에서 Alt+F7을 눌러 속성에 들어간 뒤 다음 사진처럼 추가 디렉터리를 설정해줍니다.

 

 

 

변경이 되었다면 진한 글씨로 [설정한 경로];+&~ 해당 옵션(include라면 IncludPath, lib이라면 LibaryPath) 바뀝니다.

 

 

이렇게 되면 준비는 모두 끝났습니다.

 

제가 사용하는 2010은 이렇게 옵션을 적용하면 해당 설정(win32 - 디버그)에만 적용되므로 헷갈리지는 마시구요,

 

사용은 그냥 실행이 아닌 디버그(F5)를 누르시면 됩니다.

 

중단점을 걸지 않으면 프로그램이 실행된 후 바로 꺼질테구 출력 창에 표시가 됩니다.

 

 

이름은 Visual Leak Detector 이구요, 없으면 없다. 있으면 어디에 몇 바이트라고 출력됩니다.

 


 

 

제 출력 창을 복사해보면

 

---------- Block 187 at 0x00218A18: 60 bytes ----------
  Call Stack:
    c:\users\aiko\documents\visual studio 2010\projects\chain\chain\chain.cpp (27): main
  Data:
    58 8D 21 00    A0 8D 21 00    E8 8D 21 00    30 8E 21 00     X.!...!. ..!.0.!.
    78 8E 21 00    C0 8E 21 00    08 8F 21 00    50 8F 21 00     x.!...!. ..!.P.!.
    98 8F 21 00    E0 8F 21 00    28 90 21 00    70 90 21 00     ..!...!. (.!.p.!.
    B8 90 21 00    00 91 21 00    48 91 21 00                    ..!...!. H.!.....

Visual Leak Detector detected 39 memory leaks.
Visual Leak Detector is now exiting.
'Chain.exe': 'C:\Windows\SysWOW64\dbghelp.dll' 언로드
'[444] Chain.exe: 네이티브' 프로그램이 종료되었습니다(코드: 0 (0x0)).

 

187블럭인 메모리 주소 0x00218a18번 주소부터 60바이트까지 메모리 누수가 발생했습니다.

 

소스 위치는 chain.cpp의 메인함수 + 그 메모리 내용

 

39개의 메모리 누수 검출이 감지되었습니다.

 메모리 누수 검출을 종료합니다.

 

누수 검출을 확인해주는 동적 라이브러리 dbghelp.dll을 언로드 하고 프로그램을 종료하는 출력 창 메시지입니다.

 

 

이렇게 해서 어느 정도 누수 문제를 해결할 수 있겠죠?

 

모두 많은 도움이 되시기를 바랍니다!^^





Project Description

Visual Leak Detector is a free, robust, open-source memory leak detection system for Visual C++.

It's pretty easy to use. After installing it, you just need to tell Visual C++ where to find the included header and library file.

Then it can be used with any C/C++ project simply by adding the following line to your code:
#include <vld.h> 

When you run your program under the Visual Studio debugger, Visual Leak Detector will output a memory leak report at the end of your debugging session. The leak report includes the full call stack showing how any leaked memory blocks were allocated. Double-click on a line in the call stack to jump to that file and line in the editor window.

It's a very effective way to quickly diagnose, and fix, memory leaks in C/C++ applications.

The main difference between the CRT Debug Library and VLDis that Visual Leak Detector shows you the complete callstack used for memory allocation has led to the leak.

For example:

---------- Block 1199 at 0x04BE1058: 136 bytes ----------
Call Stack:
d:\Foobar\FooLog.cpp (26): FooLog::getInstance
d:\Foobar\FooMain.cpp (75): FooMain::init
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (578): __tmainCRTStartup
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): WinMainCRTStartup
0x759A3677 (File and line number not available): BaseThreadInitThunk
0x770C9D42 (File and line number not available): RtlInitializeExceptionChain
0x770C9D15 (File and line number not available): RtlInitializeExceptionChain
Data:
9C 33 2D 6B    74 2A 2D 6B    C8 11 BE 04    00 00 00 00     .3-kt*-k ........
00 00 00 00    70 14 BB 6C    70 14 BB 6C    00 00 00 00     ....p..l p..l....
00 00 00 00    68 14 BB 6C    68 14 BB 6C    00 00 00 00     ....h..l h..l....
00 00 00 00    6C 14 BB 6C    6C 14 BB 6C    20 12 BE 04     ....l..l l..l....
00 00 00 00    CD 00 CD CD    00 00 00 00    01 CD CD CD     ........ ........
68 14 BB 6C    78 33 2D 6B    00 00 00 00    00 00 00 00     h..lx3-k ........
00 00 00 00    01 02 00 00    06 00 00 00    00 00 00 00     ........ ........
00 00 00 00    00 00 00 00    88 11 BE 04    5C 10 BE 04     ........ ....\...
00 00 00 00    20 CD CD CD                                   ........ ........

This software is provided "AS IS" without warranty of any kind.

The project was originally developed by Dan Moulding, but they are no longer supported. Features of version 2.0 are implemented by Arkadiy Shapkin (me).

Links

Last edited Sep 30 at 7:43 AM by KindDragon, version 18




download

  
  
  
  
 





http://blog.naver.com/jusias?Redirect=Log&logNo=100170133095


MFC의 메모리릭 찾는거에 익숙해져있다가 console에서도 써볼까 했는데 복잡함

vld 받아 include해주면 끝남

 

1. http://vld.codeplex.com/ 에서 vld 받음

 

2. 라이브러리랑 해더파일 위치시킴

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include 여기라든가 프로젝트 안이라든가

 

3. #include "vld.h"를 프로그램 시작위치에 넣음

 

4. 출력창에 나옴

 

5. 이것저것 설정 바꿈

http://vld.codeplex.com/wikipage?title=Configuration%20Options&referringTitle=Documentation

 

잘씀







반응형

+ Recent posts