Jump to content

Resource Management in Middle Size HTML5 Games


hima
 Share

Recommended Posts

This has been bugging me for a long time. How do you deal with resource management in HTML5? I come from a desktop game background so I know that in a middle - large size game with many resources, there will be a lot of loading and unloading resources involved.

 

But what about HTML5 game? How do we unload the already loaded imags/sounds? Or do we just set the reference to null and hope that the garbage collector will deal  with it in the future?

Link to comment
Share on other sites

Even when you set your objects to null, you have to wait for the GC to actually destroy the previous object. There is no other way to get rid of resources in javascript.

 

There are a couple of preloaders for game assets already, Tomas did also mention one already.

For your code, I recommend using requireJS which enables you to easily modularize your codebase.

Link to comment
Share on other sites

My main concern is more about unloading than preloading, but those resource manager libraries look nice, so thank you! :-)

 

I've been googling and looking through websites and it seems like there is no other way but to set it to null and wait :-/  Makes me wonder if it's possible right now to make a middle - large HTML5 game. Like, the same length as Big Fish hidden object games.

Link to comment
Share on other sites

Although you have no way of controlling the garbage collection, most browsers are pretty smart.

 

You can not expect to use the memory that you released by releasing your references straight away, that's true. However, if you're running out of RAM, GC is likely to happen before you do run out of RAM if you give it a chance. After a couple of seconds, your memory should be available again.

 

This is difficult to test precisely, because the timing of the garbage collection depends on the amount of free memory that your browser has got (and on the particular type of browser that you're using). In my limited experience, waiting 2 seconds is usually enough, but mobile Safari does sometimes take a bit longer.

 

I wouldn't think that a Big Fish hidden-object type of game requires so much RAM if you only keep data for a couple of scenes in memory. You could unload the previous one while you're playing the current one, or something like that, which would give the GC plenty of time to run.

Link to comment
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...
 Share

  • Recently Browsing   0 members

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