I have a lot of display objects in an array that I’m constantly adding and removing from stage. When removed they are not used anymore.
Considering the displayObject is not on the display list, and has no event listeners… will it be garbage collected if I use splice to remove it from the array?
Is it safer if I null the object first?
myArray[2] = null;
myArray.splice(2,1);
As long as there are no remaining references to the
DisplayObjectthen yes, removing it from the array usingsplice, or even just setting it tonullwill allow it to become a candidate for garbage collection.Update: Setting the item to
nullbefore removal from the array is redundant and will make no difference.