v3.0beta2 PoolManager maybe need refactor

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

AutoreleasePool::AutoreleasePool(const std::string &name)
: _name(name)
{
_managedObjectArray.reserve(150);
PoolManager::getInstance()->push(this);
}

void PoolManager::push(AutoreleasePool *pool)
{
_releasePoolStack.push_back(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.