Is it safe to reassign global variables with new values without causing memory leaks?
Consider the following scenario:
gUI = {};
function myFunc1() {
gUI.selectedItem = new BigArray(1000);
}
function myFunc2() {
gUI.selectedItem = new BigArray(1000);
}
function release() {
gUI.selectedItem = null;
}
Would calling myFunc1()
and myFunc2()
consecutively lead to memory leaks, or is it advisable to set the variable to null
before reassigning it?
The concern here is primarily focused on memory usage and the possibility of old memory leaking when a new value is assigned using new
.