BbaDdo :: cocos2d-x 2.2.4 & 3.x : false positive, memory leaks




결국 이제서야 코코스투디크로스 3.5 를 설치하고 설정하려니...

오래 전에 다 설치해놓고서 지금 다시보면 까마득.... 휘발성 대가리라 이렇게라도 기록해놓아야.

그리고 3.x 버젼은 렌더링을 새로 구현해서 기존 2.2 버젼보다 10배이상 빠르다고 한다.

spritebatchnode를 더 이상 쓸 필요가 없다고 함... 편해질 듯...

http://cocos2d-x.org/news/216


그런데 내부적으로 텍스쳐를 합쳐 새로 생성하는 기능이 없어졌다고 하는 듯 하는데 아직 확인을 못했다.

아직 안해봐서 그게 그건지 모름. 설마 아니겠지.

그래서 가장 안정적인듯한 2.2.3을 필요에 따라 번갈아 써야 할 듯. 공짜엔진이니까 아무래도 좋아요. 쐐쐐~


cocos2d-x 2.2.4 이상, 3.x에서 발생되는 메모리릭...

같은 코드인데도 2.2.3에서는 전혀 생기지 않았는데 발생된 기억이 난다.

4 byte 릭은 원래 생긴다는데 엔진코드를 살짝 바꾸면 없어짐.

기본 helloworld에서도 우루루 쏟아지는 메모리릭들이 vs에서 잘못 찾은 것이라고들 한다.


가양성 false positive...

  _CrtDumpMemoryLeaks can give false indications of memory leaks." data-guid="c58c57db8b6accd93a89a674a63ef875"><sentencetext style='font-family: "Malgun Gothic", Gulim, "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif !important;' xmlns="http://www.w3.org/1999/xhtml">간혹 _CrtDumpMemoryLeaks가 메모리 누수를 잘못 표시하는 경우도 있습니다.</sentencetext>  _CRT_BLOCKs or _CLIENT_BLOCKs." data-guid="d05cd00ff2d5e636da4397a2f7e83f46"><sentencetext style='font-family: "Malgun Gothic", Gulim, "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif !important;' xmlns="http://www.w3.org/1999/xhtml">이러한 오류는 내부 할당을 _CRT_BLOCK이나 _CLIENT_BLOCK 대신 _NORMAL_BLOCK으로 표시하는 라이브러리를 사용할 때 발생할 수 있습니다.</sentencetext>  _CrtDumpMemoryLeaks is unable to tell the difference between user allocations and internal library allocations." data-guid="309a37b28f5798b796144f756b6ae2df"><sentencetext style='font-family: "Malgun Gothic", Gulim, "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif !important;' xmlns="http://www.w3.org/1999/xhtml">이 경우 _CrtDumpMemoryLeaks가 사용자 할당과 내부 라이브러리 할당을 구별할 수 없게 됩니다.</sentencetext>  _CrtDumpMemoryLeaks, every internal library allocation is reported as a memory leak." data-guid="68e43a7af600c5b0e4135934898a4992"><sentencetext style='font-family: "Malgun Gothic", Gulim, "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif !important;' xmlns="http://www.w3.org/1999/xhtml">_CrtDumpMemoryLeaks를 호출한 이후에 라이브러리 할당을 위한 전역 소멸자가 실행되면 모든 내부 라이브러리 할당이 메모리 누수로 보고됩니다.</sentencetext>  _CrtDumpMemoryLeaks to report such false positives, but this has been fixed in recent releases." data-guid="cf7710ded385efefa5cd9a5292c36b5b"><sentencetext style='font-family: "Malgun Gothic", Gulim, "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif !important;' xmlns="http://www.w3.org/1999/xhtml">Visual Studio .NET 이전 버전의 표준 템플릿 라이브러리에서는 _CrtDumpMemoryLeaks가 이러한 가양성(false positive)을 보고했지만, 최신 릴리스에서는 이 문제가 해결되었습니다.</sentencetext>

 

 

https://msdn.microsoft.com/ko-kr/library/x98tx3cf.aspx





1. 일반적인 메모리릭 검사방법

win32/main.cpp 


#if defined( DEBUG ) || defined( _DEBUG )

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

#endif // DEBUG

 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR    lpCmdLine, int nCmdShow)
{

#if defined( DEBUG ) || defined( _DEBUG )
 //_CrtSetBreakAlloc(95832); //중단점
 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);


 // int *nData = new int;   //메모리릭 테스트
 // int *nData =(int*) malloc(16);
 // _CrtDumpMemoryLeaks(); //실시간 콘솔출력
#endif // DEBUG

 

// UNREFERENCED_PARAMETER( hInstance ) ;
 UNREFERENCED_PARAMETER(hPrevInstance);
 UNREFERENCED_PARAMETER(lpCmdLine);
 // UNREFERENCED_PARAMETER( nCmdShow ) ;


 // create the application instance
 AppDelegate app;
 return Application::getInstance()->run();


}


2. Visual Leak Detector를 이용한 메모리릭 검사방법

다운로드 홈페이지: https://vld.codeplex.com/releases

단점은 컴파일 속도가 조금 느려짐.

현재 최신버젼인 2.4rc2만 vs2013, 2012에서 작동확인.

RC버젼이라 아직 정식이 아니지만 잘 돌아가니 그냥 씀.


설정방법은 아래와 같이 간단.

main.cpp



#if defined( DEBUG ) || defined( _DEBUG )


#include <vld.h> 


#endif // DEBUG


최신버젼을 설치하면 자동으로 윈도우 환경변수와 vs 라입 링크를 걸어줌.

다만, include 경로는 수동으로 설정해주어야 함.

프록젝트 오른쪽클릭> 속성 > c/c++> 일반> 추가포함디렉터리>편집>c:\Program Files (x86)\Visual Leak Detector\include 추가


검사가 잘되는지 확인방법은

char *p = (char *)malloc(sizeof(char)* 1000);

이런 코드를 클래스내 아무곳에나 추가해서 확인.


vld를 제거하고 싶은 경우는 설치된 폴더로 가서 uninstall 하면 됨. 누구신지 모르지만 잘 만들었다. 


설치 참고 사이트 : http://choorucode.com/2010/09/11/visual-leak-detector-investigate-memory-leaks-in-visual-c/







끝.

'cocos2d-x' 카테고리의 다른 글

소수 Prime Numbers 판별기 C++  (0) 2021.06.04

카운터

Total : / Today : / Yesterday :
get rsstistory!