I am building a JavaScript game that creates a Level object using var:
function start() { var myGameLevel = new Level(2); } This Level object has a lot of functionality, primarily adding elements to the DOM and making them interactive. A simplification:
function Level(i) { var _difficulty = i; this.init = function(){ jQuery("#container").append(...game elements here...); jQuery("#button").on('click', function() {...}); } } My question: How can I know if the Level object created in the start function has been garbage collected or not? I aim to use only var variables so that there are no external references. When the DOM is cleared of all game elements, I EXPECT the Level object to be released from memory, but how can I be sure?