Bug: Memory leak with CCBAnimationManager


#1

The CocosBuilderTest example will leak layers when going into and out of the AnimationsTestLayer. This is because AnimationsTestLayer keeps a reference to CCBAnimationManager and CCBAnimationManager keeps a reference to AnimationsTestLayer. It’s a circular dependency. Neither class will get it’s destructor called because the reference count never drops.

Is this the correct place to report bugs and bug fixes? I never get a response to my threads and I want to make sure these are being seen.


#2

Hey, I realize that you posted 25 days ago by now. But I can across this issue today as well when I was profiling my ios app for leaks. Here is what I did to resolve this problem. You are correct about the circular dependency and because of this neither destructor gets called what I end up doing is keeping a CCBAnimationManager member variable in the same class where I load my ccbi file and I manage this variable in that class. Here is an example:

this->m_ccbAnimationManager = 0;
        CCNodeLoaderLibrary* ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();

        ccNodeLoaderLibrary->registerCCNodeLoader("MainMenuScene", MainMenuLayerLoader::loader());

        /* Create an autorelease CCBReader. */
        cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);


        ///* Read a ccbi file. */
        cocos2d::CCNode* node = ccbReader->readNodeGraphFromFile("../MainMenu.ccbi", this, &this->m_ccbAnimationManager);
        CC_SAFE_RETAIN(this->m_ccbAnimationManager);
        ((MainMenuLayer*)node)->SetAnimationManager(m_ccbAnimationManager);

        ccbReader->release();

        if(node != 0) 
        {
            this->addChild(node);
        }

        ((MainMenuLayer*)node)->ShowMenu();

and in the class’s destructor I call CC_SAFE_RELEASE_NULL:

MainMenuScene::~MainMenuScene()
{
    CC_SAFE_RELEASE_NULL(this->m_ccbAnimationManager);
}

So Franky, you might have already solved this issue yourself but maybe someone else will stumble on this same problem of circular dependency.


#3

Hi Jakub,

Thanks for the reply. I did the exact same thing.


#4

Yep, it seems to be a good fix of circular dependency.
So, could you send us a Pull Request at https://github.com/cocos2d/cocos2d-x ?
Thanks.

Jakub L wrote:

Hey, I realize that you posted 25 days ago by now. But I can across this issue today as well when I was profiling my ios app for leaks. Here is what I did to resolve this problem. You are correct about the circular dependency and because of this neither destructor gets called what I end up doing is keeping a CCBAnimationManager member variable in the same class where I load my ccbi file and I manage this variable in that class. Here is an example:
>
[…]
>
and in the class’s destructor I call CC_SAFE_RELEASE_NULL:
[…]
>
So Franky, you might have already solved this issue yourself but maybe someone else will stumble on this same problem of circular dependency.