hima Posted July 15, 2013 Share Posted July 15, 2013 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? Quote Link to comment Share on other sites More sharing options...
Tomas Posted July 15, 2013 Share Posted July 15, 2013 You had to write your own resource manager (see very simple) or you can use for example PreloadJS from Creative JS suite. Quote Link to comment Share on other sites More sharing options...
Chris Posted July 15, 2013 Share Posted July 15, 2013 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. P.Uri.Tanner 1 Quote Link to comment Share on other sites More sharing options...
hima Posted July 18, 2013 Author Share Posted July 18, 2013 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. Quote Link to comment Share on other sites More sharing options...
Gio Posted July 18, 2013 Share Posted July 18, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.