Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 팁&트릭
Delphi Programming Tip&Tricks
[243] ReportMemoryLeaksOnShutdown = True와 Indy의 의도적인 MemroyLeak...
DrK [whitekid] 5651 읽음    2008-05-02 13:11
ReportMemoryLeaksOnShutdown := True 로 설정해주면 프로그램이 종료할 때 메모리 누수가 있는 것을 검사해서 알려줍니다. FastMM이 델파이의 메모리메니저로 들어가면서 새로 생기는 기능이죠..(어느 버전부턴지는 기억이 안남..)

그런데 Indy 콤포넌트를 쓰면 항상 TIdThreadSafeInteger, TIdCriticalSection이 Leak이 되었다고 리포트가 나옵니다. Indy를 소스를 보면 주석에 의도적으로 Leak이 되도록 남겨놨다고 합니다.

그런데 계속 이게 나오니 불편합니다. 정상적인 Leak은 무시하도록 하는 기능이 없을까? 하고 뒤져봤더니 RegisterExpectedMemoryLeak(P: Pointer) 라는 procedure가 있어서 이걸 쓰면 되겠다고 했는데 변수의 포인터를 너어야되네요.. 하지만 Indy에서 나오는 Leak은 static이여서 외부에서 Pointer를 알 길이 없죠..

그래서 FastMM 최신 버전인 4.78을 봤다니 RegisterExpectedMemoryLeak의 몇가지 overload 버전이 있군요. 오호라~
프로젝트 소스 맨 처음으로 FastMM4를 추가하고 프로젝트 소스 시작부분에 다음처럼 하니.. 이제 Indy에서 만드는 의도적인 Leak은 안나옵니다.

  RegisterExpectedMemoryLeak(TIdThreadSafeInteger, 1);
  RegisterExpectedMemoryLeak(TIdCriticalSection, 2);
  ReportMemoryLeaksOnShutdown := DebugHook <> 0;

훨... 쾌적한 개발환경이.. 되었군요. 음.. 쓰고보니.. 저만 모르고 있었나요??
Lyn [tohnokanna]   2008-05-04 12:09 X
흠 그렇군요 `-`;

근데 왜 의도적인 릭을 넣었을까요?
DrK [whitekid]   2008-05-06 11:28 X
IdStack.pas에...
finalization
  // Dont Free. If shutdown is from another Init section, it can cause GPF when stack
  // tries to access it. App will kill it off anyways, so just let it leak
  {$IFDEF IDFREEONFINAL}
  Sys.FreeAndNil(GStackCriticalSection);
  {$ENDIF}


IdThread.pas에..
finalization
  // This call hangs if not all threads have been properly destroyed.
  // But without this, bad threads can often have worse results. Catch 22.
//  TIdThread.WaitAllThreadsTerminated;

  {$IFDEF IDFREEONFINAL}
  //only enable this if you know your code exits thread-clean
  Sys.FreeAndNil(GThreadCount);
  {$ENDIF}


+ -

관련 글 리스트
243 ReportMemoryLeaksOnShutdown = True와 Indy의 의도적인 MemroyLeak... DrK 5651 2008/05/02
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.