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 DisplayObject then yes, removing it from the array using splice, or even just setting it to null will allow it to become a candidate for garbage collection.

Update: Setting the item to null before removal from the array is redundant and will make no difference.

其他提示

If you need better performance I suggest you using pools instead of creating lots of objects and putting them in array. Use some linked list implementation instead of splice() operation, which is really slow.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top