Jump to content


TweenLite and memory leaks

Recommended Posts

Let's say in a class I define a private var '_tween' and instantiate a new TweenLite or Tweenmax instance in a method like so.

_tween = new TweenLite(

What happens if I call this 1000's of times? Do I need to concern myself with memory leaks? Or does TweenLite automatically take care of garbage collection. If I need to call a tween 1000's of times am I always better to use the static variation instead?

Link to comment
Share on other sites

If when you say "call this 1000's of times" you just mean that you're playing that same tween instance many times, that's absolutely fine - no need to worry about memory "leaks". If, however, you meant creating 1000's of instances of a class that has a _tween variable (so you're creating 1000's of tweens and maintaining a reference to all of those class instances in your app), that could potentially be a problem, but it has nothing to do with GSAP - that's just how ActionScript works. 


The key here is whether or not you're maintaining your own references somewhere that tie back to the root. Again, that's true of ANY variable/object. I'd strongly encourage you to read up on garbage collection and how Flash handles it (like what things become eligible and which don't). 


For example, if you have a "myObjects" array variable at the root of your app and you dump 1000 instances of MyObject classes into the array, and each MyObject has a _tween property that it populates with a TweenLite in its constructor, that means you've got 1000 MyObjects and 1000 TweenLite instances. If you never clear that array or null the variable, the garbage collector cannot sweep those MyObjects or associated TweenLite instances away (nor should it - what if you have code that tries to reference those later?) 


In general, you pretty much never need to worry about "memory leaks" with GSAP at all. But it is certainly possible to write your own code in a way that prevents gc.

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.