Hi, everyone. I almost finished with one level of my game. I extended MyLevel class from CCLayer and adding it to the screen using [[CCDirector sharedDirector] pushScene:[SecondLevel scene]]; In my level class I have "scene" function : CCScene *scene = [CCScene node]; [scene addChild:[SecondLevel node]]; return scene; And then I need to remove level from screen I am using (right inside the level itself): [[CCDirector sharedDirector] popScene]; The problem - memory usage. I checked my level with Leaks Instrument tool, because my level using huge amount of memory (but this is normally, because there is many resources in use), and I want to be sure that I relesase all used memory. So, during test I found that I didn't have any memory leaks at all. Nothing was shown on Leaks tab. BUT in Allocations tab I found that my level LiveBytes value getting near 450MB and (this is main confusion) this number didn't changed after I calling: [[CCDirector sharedDirector] popScene]; So the memory that my level used still busy even after it was removed from screen. Maybe there is some other reasons except memory leaks of this behavior, or I need manualy release Scene that was poped from the CCDirector?
Hi, I’m using CCDirector::sharedDirector()->replaceWithScene(newScene); (or something like that). Everything is fine, resources are released. Maybe you do not dealloc something in the destructor?
Hi, thanks for the answer. I wrote that I didn’t have any memory leaks or something like this during testing. Maybee I missed something in dealloc function, but the active bytes didn’t changing at all! Looks like I didn’t dealloc anything but this is not true.
I will try not just pop scene but to replace it with other, maybe this will work.
Not sure, but I think memory will be actually released when autorelease pool will be cleaned (will automatically happen in the end of game loop iteration by default). Also the texture cache can be cleaned.
Ok, thank you for your help.
I added :
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames]; [[CCTextureCache sharedTextureCache] removeAllTextures];
And some memory (about 50% of live bites was deallocated).
About autorelease pool, you see I can’t wait then it will be released, because I am calling popScene and then immdiately push another scene. And it crashes application during testing on real device, because of not enougth memory. But suggestion about texture cash gave some progress.
Okay, in dealloc function I changed the way I am destroying b2World and b2DebugDraw objects. I used : free(World); free(DebugDraw). functions. I changed it to : delete World; delete DebugDraw; And another big amount of memory was released. 46MB left, but this is suitable I think. Instead of 500MB.
You can clean autorelease pool manually too.
Can you please provide an example string how to do it?
Thanks a lot. I will try it.