Projects > cpp > Issues > Bug #3415

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

Potential SERIOUS MEMORY LEAK on CCDirector::popScene(void)

Bug #3415 [Closed]
jiangweiff 2013-12-17 07:46 . Updated about 2 years ago

I found CCDirector::popScene may cause memory leak on some occasions.
The thing is, when u popScene more than once in a single frameupdate, like

CCDirector::sharedDirector()::popScene()
CCDirector::sharedDirector()::popScene()

then everything between current scene and last scene will be leaked out. Which could be a lot of stuffs out there.
I modified the code as below and it worked fine until now.

void CCDirector::popScene(void)
{
    CCAssert(m_pRunningScene != NULL, "running scene should not null");

    CCScene *current = (CCScene*)m_pobScenesStack->lastObject();
    if( current->isRunning() )
    {
        current->onExit();
    }
    current->cleanup();

    m_pobScenesStack->removeLastObject();
    unsigned int c = m_pobScenesStack->count();

    if (c == 0)
    {
        end();
    }
    else
    {
        m_bSendCleanupToScene = false;
        m_pNextScene = (CCScene*)m_pobScenesStack->lastObject();
    }
}
walzer@cocos2d-x.org 2014-10-08 02:50

Redmine issue system is closed, we are using github issue system instead.

This issue was moved to https://github.com/cocos2d/cocos2d-x/issues/8284

Atom PDF

Status:Closed
Start date:2013-12-17
Priority:Low
Due date:
Assignee:-
% Done:

100%

Category:all
Target version:-

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.