From 1eb991df5976616dfbc1dfae884f8f444e351534 Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Tue, 3 Jun 2014 18:57:52 +0800 Subject: [PATCH] bugfix related to AutoreleasePool's PoolManager * duplicated AutoreleasePool added to PoolManager in PoolManager::getInstance() * redundant pop_back() in PoolManager::~PoolManager() --- cocos/base/CCAutoreleasePool.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/cocos/base/CCAutoreleasePool.cpp b/cocos/base/CCAutoreleasePool.cpp index d5e35a01c4..25478aec5e 100644 --- a/cocos/base/CCAutoreleasePool.cpp +++ b/cocos/base/CCAutoreleasePool.cpp @@ -111,8 +111,7 @@ PoolManager* PoolManager::getInstance() { s_singleInstance = new PoolManager(); // Add the first auto release pool - s_singleInstance->_curReleasePool = new AutoreleasePool("cocos2d autorelease pool"); - s_singleInstance->_releasePoolStack.push_back(s_singleInstance->_curReleasePool); + new AutoreleasePool("cocos2d autorelease pool"); } return s_singleInstance; } @@ -134,7 +133,6 @@ PoolManager::~PoolManager() while (!_releasePoolStack.empty()) { AutoreleasePool* pool = _releasePoolStack.back(); - _releasePoolStack.pop_back(); delete pool; } @@ -164,16 +162,9 @@ void PoolManager::push(AutoreleasePool *pool) void PoolManager::pop() { - // Can not pop the pool that created by engine - CC_ASSERT(_releasePoolStack.size() >= 1); - + CC_ASSERT(!_releasePoolStack.empty()); _releasePoolStack.pop_back(); - - // Should update _curReleasePool if a temple pool is released - if (_releasePoolStack.size() > 1) - { - _curReleasePool = _releasePoolStack.back(); - } + _curReleasePool = _releasePoolStack.empty() ? nullptr : _releasePoolStack.back(); } NS_CC_END