Jump to content

Does calling stop() on a tween automatically remove / dispose of it?


Recommended Posts

Hi, there are three classes: Tween, TweenData, TweenManager.

Tween contains at least one TweenData. TweenData are not importatn for us now. TweenManager is keeping array of currently running tweens and in its update() calls update on all tweens. If tween is finished then its update() method returns false and it is removed from TweenManager.

 When you call stop() on tween it calls manager's remove() function and it does not remove tween immediately. Instead it sets tween's pendingDelete = true. In next turn when manager in update() calls update() on this tween, pendingDelete flag is checked and if true, tween update() immediately ends, returns false and tween is removed from manager. There is no place where to reset pendingDelete to false and thus make tween reusable!

 - if you plan to have reusable tween (tween you want to call start() on multiple times), then keep reference to it, but never call stop() on it,
 - any tween (reusable, or one, you called stop() on and can not be reused again), which you keep reference on, is not removed from memory,
 - any tween you do not keep reference on is removed from memory when finished or stopped (in some unknown time, when garbage collector decides). It is first removed from manager and as there is no reference it is free to be garbage collected.

 If you want to do something wild, you can make all tweens reusable, even those, you called stop on. But you would have to do things described here:


Link to comment
Share on other sites


  • Recently Browsing   0 members

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