Removing objects from memory... Is it possible?
BasiliosZ

I was wondering if it is possible to remove a WADE object that is not needed anymore to recover the memory, for example for the sprite of a destroyed enemy. Is it necessary at all to do the garbage collection, or is it automatic? I've been going over the tutorial but I must have missed it.

All 2 Comments
Gio

If it's a normal javascript object, such as a WADE Sprite, just setting all the references that you have to it to "null" (or to something else) would make it collectable by the garbage collector. Basically, as long as you don't have any reference to it, it's going to be garbage-collected by the javascript engine of your browser.

Assets such as images are different, because WADE has its own asset manager, and keeps track of which images and sounds have been loaded, and keeps them in memory. To free up the memory used by an image, you can use wade.unloadImage(). However all this does, is releasing all the references to that image so that it can be garbage-collected. There is no guarantee as to when the object is actually removed from memory - in general, browsers tend to do it only when they're running low on available memory.

BasiliosZ

Ok, good to know.

Post a reply
Add Attachment
Submit Reply
Login to Reply