Jump to content

Remove assets from memory - Cocoon&Phaser


Kiwiboy
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...