Search code examples
objective-ccocos2d-iphonereleasedealloc

Cocos2d not dealloc-ing the scene (again)


this is my first post so don't go too rough on me.

I have a problem with cocos2d. Im making a game with a HUD layer and a game layer. When I call replace main menu scene with [ClassicGameLayer scene] my HUD and game layer get init-ed this way:

+ (CCScene*)scene
{
CCScene *scene = [CCScene node];

HudLayer *hud = [[[HudLayer alloc] initWithMode:1] autorelease];
ClassicGameLayer *layer = [[[ClassicGameLayer alloc] initWithHUD:hud] autorelease];

[scene addChild:hud z:hudZ];
[scene addChild:layer z:layerZ];

return scene;
}

and when the user fails the game HUD layer calls

[[CCDirector sharedDirector] replaceScene:[GameOverLayer sceneWithMode:integer andScore:points]]];

dealloc of the HUD layer gets called but dealloc of the ClassicGameLayer is never called. I googled almost everything I could think of but still no luck. Does anybody know whats causing me this problem? And if so how can I fix it? Every other scene is being released properly i think :)


Solution

  • If your autorelease pool never gets to the place where it deallocates stuff, it will never release any memory. I had this issue once with a Mac app I was writing. It won't show up as a memory leak in Instruments, either.

    I recommend not using autorelease if you are having this problem.