Safely deleting a scene element in easeljs (createjs)

I have an application with a small animation class. The animation class creates a canvas (using jquery), creates the createjs.Stage element that uses this canvas, and then this stage element is used to perform some animations for a short period of time. When the animation is complete, I want to clear everything so that the new animation can do the same.

When using the Stage class, you need to add several listeners, for example createjs.Ticker.addEventListener(stage) , and you can add a DOMEventlistener. I tried to figure out how to safely delete the scene and the canvas, and so far I have found some information about the need to set the canvas of the scene to null ( stage.canvas = null; ) before setting the stage to null ...

I also found a method in the scene class: removeAllEventListeners() .

So here are my questions:

1) If the canvas and the scene are added only to the animation class, is it enough to do this:

 var animation = new Animation() // do some stuff, call some methods on the animation object, and then: animation = null; 

You will have to manually remove the canvas from the body using jqeury.remove() or something to get rid of the canvas, I think ...

2) If the above method is not correct, can removeAllEventListeners be called when the animation is done before setting the stage to null?

I'm not at all sure how to make sure everything is garbage collected, so any advice is welcome!

+6
source share

Source: https://habr.com/ru/post/952201/


All Articles