in my app I'm having 3 ccscenes which are reused when needed,
before reusing, I'm removing layer from scene to reuse, create new layer add it to the scene and present later to the user when requested
each scene has some objects and background (also using box2d)
the problem I'm facing is with real used memory, its constantly increasing:
without adding background and objects its ok,
in layer init method I'm adding background sprite like so:
NSString *backgroundPath = [[ResourceManager sharedManager] pathForResource:page.description.bgImage];
if (backgroundPath) {
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGB565];
CCSprite *background = [CCSprite spriteWithFile:backgroundPath];
background.anchorPoint = ccp(0, 0);
[self addChild:background z:0 tag:kTagBackground];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_Default];
}
(i was also trying here to create a texture with cctexturecache and create sprite this way, but effect was the same)
then before reusing a scene I'm calling a method to clean up its current layer where i want to remove this background texture from memory like so:
CCSprite *bg = (CCSprite*)[self getChildByTag:kTagBackground];
if (bg) {
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromTexture:bg.texture];
[[CCTextureCache sharedTextureCache] removeTexture:bg.texture];
[bg removeFromParentAndCleanup:YES];
}
but unfortunately memory in activity monitor (instruments its increasing of 2mb, sometimes more then drops but sill its +2mb) causing a crash eventually
am i doing something wrong?
is reusing ccscenes a good idea?