문제

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