dictionary - Can I have a javascript object remove itself from memory by having it set its map value to null? -
would game object remove memory when kill game called?
var gamesmap = {}; var count = 0; function game (players, privategame) { if (privategame) this.privategame = true; else this.privategame = false; this._id = count++; this.players = players; this.judge = this.setjudge(); this.killgame() = function() { gamesmap[this._id] = null; } }
if there no other references particular game object (including event handlers , other lasting things that), clearing last reference clearing reference in gamesmap make eligible garbage collection when killgame() method finishes executing. but, fact able call obj.killgame() means else has reference reference needs released too.
i suggest rather set property null delete property in map this:
delete gamesmap[this._id]; so you're cleaning after game done.
Comments
Post a Comment