Kiwiboy

Remove assets from memory - Cocoon&Phaser

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!

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
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?

Share this post


Link to post
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+.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.