Jump to content
Search Community

Garbage collection for repeated animation

chenxin test
Moderator Tag

Recommended Posts

Let's say I have a repeated animation, like this: 

 

const tl = new TimelineMax({
  repeat: -1, 
})
tl.to(...)

 

Q1:  If I pause the animation by calling tl.pause() , when will this animation be garbage collected?

Q2:  If I kill the animation by calling tl.kill(), when will this animation be garbage collected ?

Q3:  For a repeated animation that has already been paused, is it necessary to call Kill() method?

 

 

Link to comment
Share on other sites

6 hours ago, chenxin said:

Q1:  If I pause the animation by calling tl.pause() , when will this animation be garbage collected?

Pausing an animation doesn't make it available for garbage collection (otherwise what if you wanted to resume()?) 

 

6 hours ago, chenxin said:

Q2:  If I kill the animation by calling tl.kill(), when will this animation be garbage collected ?

That's up to the browser. GSAP doesn't control when garbage collection occurs. As long as you killed the animation and you no longer maintain any references to it in your own code (like a variable), the browser will sweep it away the next chance it gets. 

 

6 hours ago, chenxin said:

Q3:  For a repeated animation that has already been paused, is it necessary to call kill() method?

If you want to make it available for garbage collection, yes. 

 

To be clear, the global timeline has autoRemoveChildren enabled which means that when any of its child animation completes, it gets removed and GSAP no longer maintains references to it, thus it can be garbage collected (assuming you don't maintain your own references to it). 

 

Does that help? 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...