Ryan Lee Posted July 15, 2022 Share Posted July 15, 2022 Hi! As the title says, I want to know whether we need to release manually to achieve the purpose of performance optimization. for example: Some animations are set in component A, and I guess there are some monitoring methods will be implemented. Like: onresize or onscroll... When we leave or destroy components, do these monitors still exist? Or do we need to destroy it manually when we leave? Like vuejs: destroyed() { // gsap.clear() or gsap.destroy() any methods like this ? } Link to comment Share on other sites More sharing options...
Solution GreenSock Posted July 15, 2022 Solution Share Posted July 15, 2022 In the vast majority of cases you don't need to worry about killing things manually, no. When an animation finishes running, it is made eligible for garbage collection from the core. The only exceptions I can think of are: If you have an infinitely repeating tween ScrollTriggers You can kill all the ScrollTriggers on a page like this: ScrollTrigger.getAll().forEach(t => t.kill()) You can clear all animations an delayedCalls like this: gsap.globalTimeline.clear(); But again, that's only useful if you're dynamically loading new content and you want to flush all the old stuff WITHOUT the browser navigating to a new address. Does that answer your question? 1 Link to comment Share on other sites More sharing options...
Ryan Lee Posted July 15, 2022 Author Share Posted July 15, 2022 @GreenSock oh thanks! This is what I want. I guess the listener of scrolltrigger was still working when my component was destroyed. So, this is what I want to do: ScrollTrigger.getAll().forEach(t => t.kill()) haha! thank your again! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now