Memory not being cleared when moving between scenes

Hi,

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?

4 Likes

Hi,

Any one have solution for this. This not only happen on iOS but also on web desktop when I ran it on Opera. I haven’t tested on Android yet

@slackmoehrle @nite @pandamicro @jare I know it’s late now, but please can you guys take a look at this issue in the morning your time

Cocos Creator use a different scene api, might be best to ask @pandamicro

Also @nantas2 might be able to help.

Hi @nantas2 @pandamicro,

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

Hi All,

I need an assistance about this topic, too.

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();
}

Still waiting for assistance too

it would be great if we can get a response about it. Im working on my 2nd game and Im worried about this might be an issue.

I guess this is bad timing as everyone is enjoying Christmas with family. Lets wait a few days and ping back if no response.

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!

1 Like

Yeah, Im doing this too. It is a good solution for small games without many scenes. But we still need to understand if this is a bug or what.

Thank you and Merry Christmas!
Can you be more specific on how to do it. I’m not familiar with case in which ARC disabled

Any update on this topic? If we cannot have solution for optimizing memory usage, how we suppose to publish game to users

Still waiting for assistance about this issue.

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?

Hi,

Could you find a proper solution with these memory problems?