Jump to content
Search Community

Tweens / targets being held in memory

rich_earth test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts



I'm using TweenMax with PIXI.js  to tween positions of objects...     I have lots of objects being spawned, tweened and then destroyed.   When I just create an object and then destroy it and make it null, it gets removed from memory  (using Chrome heap snapshot to check).   If I create the object then tween it,  then call kill() on the tween and destroy my object,  it the object hangs about in memory.     

Its seems that TweenMax is keeping reference to the target I set the tween on, even after I have called kill() on the tween,  in some kind of lookup dictionary in TweenMax.   So I'm building up a lot of objects in memory that I can't clear, which is a big problem.   Is there a way to flush this cache of objects in TweenMax when I kill a tween?




Link to comment
Share on other sites

Thanks for the response.   I thought this but for some reason in my test the objects just hang around indefinitely and build up in memory.  Could be something to do with the dev tools / what I'm logging to console, so I'll build a proper test to post here.   For now I am manually removing the target from _internals.tweenLookup when I kill() and its back to using no memory again. Thanks

  • Like 2
Link to comment
Share on other sites

OK thanks.  I suppose the reason is also me being curious. :)   More so in cases with a game engine where you might be creating hundreds of new objects per second or testing memory / debugging its just useful to know,  but I can't think of a real case where I'd be creating hundreds or tweens like that.  Thanks though!

Link to comment
Share on other sites

When I need to create and tween hundreds of new objects every second, I usually use an object pool so I can reuse them. When respawning, I call invalidate to adjust the start and end values for any tweens that need to be updated. Yes, you sacrifice memory, but performance will usually be better as garbage collection will happen less often.


  • Like 4
Link to comment
Share on other sites

Yeah, sorry about that but sometimes we add some features that we intentionally leave undocumented because we're not sure how useful they'll be in real-world situations, so we kinda leave the door open and see how many times it comes in handy for real-world situations. autoSleep is one of those that almost nobody seems to need or care about :)

  • Like 1
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...