Merge pull request #6959 from kezhuw/bugfix_autorelease_pool_manager

Bugfix autorelease pool manager
This commit is contained in:
minggo 2014-06-04 14:31:30 +08:00
commit 7bf2be6033
3 changed files with 10 additions and 16 deletions

View File

@ -111,8 +111,7 @@ PoolManager* PoolManager::getInstance()
{ {
s_singleInstance = new PoolManager(); s_singleInstance = new PoolManager();
// Add the first auto release pool // Add the first auto release pool
s_singleInstance->_curReleasePool = new AutoreleasePool("cocos2d autorelease pool"); new AutoreleasePool("cocos2d autorelease pool");
s_singleInstance->_releasePoolStack.push_back(s_singleInstance->_curReleasePool);
} }
return s_singleInstance; return s_singleInstance;
} }
@ -125,6 +124,7 @@ void PoolManager::destroyInstance()
PoolManager::PoolManager() PoolManager::PoolManager()
{ {
_releasePoolStack.reserve(10);
} }
PoolManager::~PoolManager() PoolManager::~PoolManager()
@ -134,7 +134,6 @@ PoolManager::~PoolManager()
while (!_releasePoolStack.empty()) while (!_releasePoolStack.empty())
{ {
AutoreleasePool* pool = _releasePoolStack.back(); AutoreleasePool* pool = _releasePoolStack.back();
_releasePoolStack.pop_back();
delete pool; delete pool;
} }
@ -143,7 +142,7 @@ PoolManager::~PoolManager()
AutoreleasePool* PoolManager::getCurrentPool() const AutoreleasePool* PoolManager::getCurrentPool() const
{ {
return _curReleasePool; return _releasePoolStack.back();
} }
bool PoolManager::isObjectInPools(Ref* obj) const bool PoolManager::isObjectInPools(Ref* obj) const
@ -159,21 +158,12 @@ bool PoolManager::isObjectInPools(Ref* obj) const
void PoolManager::push(AutoreleasePool *pool) void PoolManager::push(AutoreleasePool *pool)
{ {
_releasePoolStack.push_back(pool); _releasePoolStack.push_back(pool);
_curReleasePool = pool;
} }
void PoolManager::pop() void PoolManager::pop()
{ {
// Can not pop the pool that created by engine CC_ASSERT(!_releasePoolStack.empty());
CC_ASSERT(_releasePoolStack.size() >= 1);
_releasePoolStack.pop_back(); _releasePoolStack.pop_back();
// Should update _curReleasePool if a temple pool is released
if (_releasePoolStack.size() > 1)
{
_curReleasePool = _releasePoolStack.back();
}
} }
NS_CC_END NS_CC_END

View File

@ -163,8 +163,7 @@ private:
static PoolManager* s_singleInstance; static PoolManager* s_singleInstance;
std::deque<AutoreleasePool*> _releasePoolStack; std::vector<AutoreleasePool*> _releasePoolStack;
AutoreleasePool *_curReleasePool;
}; };
// end of base_nodes group // end of base_nodes group

View File

@ -75,6 +75,11 @@ void ReleasePoolTestScene::runThisTest()
} }
// object in pool2 should be released // object in pool2 should be released
{
new AutoreleasePool;
PoolManager::destroyInstance();
}
Director::getInstance()->replaceScene(this); Director::getInstance()->replaceScene(this);
} }