threedollarbill Posted July 20, 2016 Share Posted July 20, 2016 Does calling stop() on a tween automatically remove / dispose it from memory? Also, I read here http://www.html5gamedevs.com/topic/3462-remove-tween-when-its-complete/ that a tween is automatically removed once it's completed. Is this still the case? I just want to make sure I'm handling my tweens properly so I don't have any memory leaks. Link to comment Share on other sites More sharing options...
Tom Atom Posted July 20, 2016 Share Posted July 20, 2016 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! So: - 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 More sharing options...
threedollarbill Posted July 20, 2016 Author Share Posted July 20, 2016 thank you for the extensive insight @Tom Atom! Link to comment Share on other sites More sharing options...
Recommended Posts