I have a case where I have a variable in my JavaScript that will be used to store the reference to several instances of a class. The class creates a div based window, kind of like a lightbox, and then when I call the class' removeWindow method, the div window elements are removed from the DOM. So a sequence might be like this:
var divWindow = null;
divWindow = new DivWindowClass(...);
/* do some stuff with the window */
divWindow.removeWindow();
Later on in the code I create a window again with different content, but I also want to be able to check if the divWindow variable is referencing anything.
Is it correct to just do:
divWindow.removeWindow();
divWindow = null;
if (divWindow == null) { /* etc. */ }
/* later in the code */
divWindow = new DivWindowClass(...); /* with different content than first one */
or does that cause memory issues with the JavaScript garbage collection? If I set divWindow to null, will that signal to the garbage collection to gather up my object and get rid of it, or is there something else I need to do to be tidy?
As always, thanks in advance!
deleteit if you want.deleteon identifiers declared with thevarstatement (alsofunctiondeclarations, function argument names, etc) will have no effect (they are bound as non-configurable properties of its environment record), moreover this is disallowed on strict mode,delete identifier;is treated as aSyntaxError. See also: understanding deletevar a = 3; delete a, accessingais not possible anymore.