I am confused by this since I saw several different comments. I read a javascript book that mentions setting global variables to zero is good practice (assuming there are no other references), and GC restores memory for this variable in the next step. I saw other comments that say that global variables are never deleted by the GC.
Also when programming javascript in the OOP framework, what happens if I have something like this (where the game is in a global context):
var game = {}; game.level = 0; game.hero = new hero(); //do stuff game.hero = null;
Since the hero lives inside an object that is stored in a game that is in a global context, if I set the hero, for example, to null, will it be selected by GC?
javascript garbage-collection
user2000950
source share