I found out after I switching back and forth between scenes, my game becoming slow, then I started observing memory usage with xCode, memory not being cleared when moving between scenes. my game kept eating up memory.
As my knowledge, scenes are not cached, whenever I call cc.director.loadScene, previous scene will be destroyed. Am I missing any importance guidance?
Have you guys taken a look at my issue, I’m about to release my game really soon, it’s in optimizing performance phase already, I really really need your help
In my game scene, I load some assets (sprite frames, textures) dynamically using cc.Loader and before switching to next scene I try to release them from loader and remove from texture cache. I remove related sprite frames before cleaning texture cache. Also, I have set auto release option on scene and dynamically loaded sprite frames.
My observation is that it seems working on browser when I check resources after scene changes by opening developer tools multiple times. However, on IOS I see that memory is filling up every time my game loads this scene again.
I have seen the following code while working on some things. Could I expect that scene data which is no longer in use could be deleted if this warning occurs?
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
cocos2d::Director::getInstance()->purgeCachedData();
}
I have the same issue, but decided to do a workaround after two days on ‘Instruments’ and XCode, trying to understand why my objects weren’t released though I made sure the retain-release pairs were correct.
I ended up retaining my scenes, which is possible for me since I’m not creating many big scenes. I then have functions endGame and startGame, which set the game up again reusing the old scene objects.
I hope you are able to fix your issue. Merry Christmas!
I actually am facing a similar problem, however with a different problem than you do. I opted to not use multiple scenes, and instead just one scene where I dynamically load prefabs and instantiate them ( like enemies and what not). After not needing them, then I’d delete the nodes and release them.
I find that after sometime, the memory starts to build up and eventually causes lower end phones to crash. I tried using xcode to do a stack trace for leaks, but then it only points to the general update called by cocos for every frame. Anyone has a better way or any gotchas/tips to look out for?