1

I am using EaselJS and Box2DWeb to create an arrow shooting game. Every time an arrow collides with another body, it dies, and I call this function:

if(body.dead){
    removeActor(body.GetUserData()) //the user data is the actor object (sprite) of the arrow
    world.DestroyBody(body);
    delete body;
    bodies.splice(i, 1);
    i--;
}

and the removeActor function:

    // remove actor and it's skin object
var removeActor = function(actor) {
        if(actor){
    stage.removeChild(actor.skin);
    actors.splice(actors.indexOf(actor),1);
            delete actor;                
        }
}

I tried continuously creating arrows and checking to see if the memory has been freed (using chrome task manager), but the memory used only increases. Is there a way for me to completely remove these objects from memory?

Jack Sparser
  • 75
  • 2
  • 10
  • 3
    Once there are no references to an object, it'll be freed next time the garbage collector kicks in. If your memory is not being reclaimed, you're holding references to your objects somewhere else. The `delete body;` and `delete actor;` lines do nothing. – silly little me Apr 24 '13 at 00:55
  • Except for IE, you can't force the garbage collector to run directly from the page. Even then, you don't know that it will remove them from memory. Check your other code to make sure there's not a problem there (e.g. closures not handled properly). – Qantas 94 Heavy Apr 24 '13 at 03:20

0 Answers0