Kiwiboy Posted January 22, 2015 Share Posted January 22, 2015 Hi peeps, posted this in the Common Phaser & CocoonJS issues topic as well, but no answer as of yet. This is what's keeping me from finishing the game pretty much so felt like I had to make it it's own topic as well.I've been having some struggles with memory as of late. At first I loaded everything in preload.js which worked fine in my other smaller games, and I use shutdown() for the first time and clear every object when leaving a state which certainly makes the game smoother.But then when making my third world for the game I recieved memory warnings. So I decided to load the necessary parts of each world in their preload-functions, now the problem I'm having is removing them when entering a new one. Say when I'm done with world 1 and enter world 2, I want to clear the loaded assets only used in world 1. I've tried cache.removeImage(key), which alone did not quite work as I'd like, since it doesn't quite clear it right away. Then I've read about cocoons feature .dispose() which I then tried like this: cache.getImage(key).dispose()cache.removeImage(key) I've tried in some other orders too, and a little with PIXI(but since that's part of removeImage I didn't look that much into it), but long story short(er); what's the best way to clear assets from memory, using cocoon and phaser, since I want to load them every time I enter each world. I don't want to do it in an incomplete way like I did with removing objects from states before. Cheers! clark 1 Link to comment Share on other sites More sharing options...
Toknos Posted January 25, 2015 Share Posted January 25, 2015 I would also love to know this! Anybody? Kiwiboy 1 Link to comment Share on other sites More sharing options...
Kiwiboy Posted January 27, 2015 Author Share Posted January 27, 2015 I hate bumping, but I'll still do it Link to comment Share on other sites More sharing options...
redsheep Posted January 28, 2015 Share Posted January 28, 2015 If you've define all the assets in each preload method of state, and want clear ALL the asset before switch to other state, you can try the 'clearCache' parameter of 'start' method. like game.state.start('next',true,true) Link to comment Share on other sites More sharing options...
vulvulune Posted January 28, 2015 Share Posted January 28, 2015 cache.removeImage(key) should be enough to release the memory. Did you try to check in a desktop browser if the memory is released correctly? (For example with the memory diangostics Tools of Internet Explorer (https://msdn.microsoft.com/en-us/library/ie/dn255003(v=vs.85).aspx)). If your memory issues occured only with cocoon, you should contact them to try to find a solution. Did you try with the canvas+ or with webview? evg 1 Link to comment Share on other sites More sharing options...
Kiwiboy Posted January 28, 2015 Author Share Posted January 28, 2015 Thanks for the replies! I don't load all assets every state change unfortunately, and I don't really want to. And yes, cache.removeImage(key) does release the memory, just not right away, but when the garbage collector wants to. Cocoon controls that so I should find a way to force the gc to do it's thing. Just not sure how. And I use canvas+. Link to comment Share on other sites More sharing options...
Kiwiboy Posted February 2, 2015 Author Share Posted February 2, 2015 Anyone got any insight on cocoonjs dispose feature and how to use it? I think knowing how that works is what I need. Otherwise I might have to go with just removeImage and trust that the gc removes the stuff if it's almost getting clogged. Link to comment Share on other sites More sharing options...
Recommended Posts