From 768828ec295e16e6ebd1c3ad4d8a132b0f0006e8 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 18 Sep 2013 17:16:31 +0800 Subject: [PATCH] add term logic of application to prevent memory leak (for desktop such as linux, mac, windows) --- cocos2dx/platform/linux/CCApplication.cpp | 8 +++++++- cocos2dx/platform/mac/CCApplication.mm | 8 ++++++++ cocos2dx/platform/win32/CCApplication.cpp | 9 ++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cocos2dx/platform/linux/CCApplication.cpp b/cocos2dx/platform/linux/CCApplication.cpp index a9cfc080cc..0534b83208 100644 --- a/cocos2dx/platform/linux/CCApplication.cpp +++ b/cocos2dx/platform/linux/CCApplication.cpp @@ -60,7 +60,13 @@ int Application::run() usleep((_animationInterval - iCurTime+iLastTime)*1000); } } - + /* Only work on Desktop + * Director::mainLoop is really one frame logic + * when we want to close the window, we should call Director::end(); + * then call Director::mainLoop to do release of internal resources + */ + Director::getInstance()->end(); + Director::getInstance()->mainLoop(); return -1; } diff --git a/cocos2dx/platform/mac/CCApplication.mm b/cocos2dx/platform/mac/CCApplication.mm index 460574169b..5959a2774e 100644 --- a/cocos2dx/platform/mac/CCApplication.mm +++ b/cocos2dx/platform/mac/CCApplication.mm @@ -60,6 +60,14 @@ int Application::run() Director::getInstance()->mainLoop(); pMainWnd->pollEvents(); } + + /* Only work on Desktop + * Director::mainLoop is really one frame logic + * when we want to close the window, we should call Director::end(); + * then call Director::mainLoop to do release of internal resources + */ + Director::getInstance()->end(); + Director::getInstance()->mainLoop(); return true; } diff --git a/cocos2dx/platform/win32/CCApplication.cpp b/cocos2dx/platform/win32/CCApplication.cpp index 5f52412406..a29e842143 100644 --- a/cocos2dx/platform/win32/CCApplication.cpp +++ b/cocos2dx/platform/win32/CCApplication.cpp @@ -64,7 +64,14 @@ int Application::run() Sleep(0); } } - + + /* Only work on Desktop + * Director::mainLoop is really one frame logic + * when we want to close the window, we should call Director::end(); + * then call Director::mainLoop to do release of internal resources + */ + Director::getInstance()->end(); + Director::getInstance()->mainLoop(); return true; }