v3.0beta2 PoolManager maybe need refactor

v3.0beta2 PoolManager maybe need refactor
0.0 0


`PoolManager* PoolManager::getInstance()
if (s_singleInstance == nullptr)
s_singleInstance = new PoolManager();
s_singleInstance->_curReleasePool = new AutoreleasePool(“cocos2d autorelease pool”);
return s_singleInstance;

AutoreleasePool::AutoreleasePool(const std::string &name)
: _name(name)

void PoolManager::push(AutoreleasePool *pool)
_curReleasePool = pool;

When first call PoolManager::getInstance(), it will create a new AutoreleasePool-we call it ‘A’, and then call function push() to save itself into PoolManager’s _releasePoolStack in AutoreleasePool’s Constructor, so ‘A’ is in PoolManager’s _releasePoolStack right now. After create ‘A’, _curReleasePool is pointing ‘A’ in function getInstance(), then s_singleInstance->_releasePoolStack.push_back(s_singleInstance->_curReleasePool), just like s_singleInstance->_releasePoolStack.push_back(‘A’), so ‘A’ is saved in _releasePoolStack again.
I think just save one time enough.


Can anyone explain it?
Maybe i’m wrong.


I think your problem is mixing the concepts of autorelease pool and the pool manager. Try to separate these two concepts and rereading the source code may help you understand better.


Thinks @0owen
In my mind, PoolManager managers AutoreleasePool, but there is no need to storage the first AutoreleasePool twice.
When closing game, PoolManager will pop the first AutoreleasePool twice, and then delete it.
If just storage it once, will save memory and reduce the process.