# Tween and Garbage Collection problem

**URL:** <https://forum.kirupa.com/t/tween-and-garbage-collection-problem/271662>\
**Category:** flash\
**Created:** [September 26, 2008, 2:47am UTC](https://forum.kirupa.com/t/tween-and-garbage-collection-problem/271662 "2008-09-26T02:47:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![elliottg](https://avatars.discourse-cdn.com/v4/letter/e/b77776/32.png) [@elliottg](https://forum.kirupa.com/u/elliottg)\
**Post date:** [September 26, 2008, 2:47am UTC](https://forum.kirupa.com/t/tween-and-garbage-collection-problem/271662/1 "2008-09-26T02:47:56Z")

</div>

No matter what I do I cannot solve a tween AS3 Garbage Collection problem I am having that is wreaking havoc on my tween instances working correctly/consistently. Some Sprites never tween at all, some do but only part way. And it effects different ones almost each time.

I have read a fair amount recently on AS3 Garbage Collection and improperly referenced Tweens and other asynchronous instances getting picked up in mid process. I am experiencing the signature inconsistent behaviour that the I have read of.

I have tried using class level Static and non static properties to store references to my Tween instances so they will not be marked for GC. No luck. I have placed references to them in Class level Arrays, I have also used TweenMax’s static to() Method that insures that it will shield it from GC and its alt. non Static constructor instantiation, with persist:true. I also implemented another custom package; GCSafeTween(), other users said it does as it should, but it’s not working in my case.

To test the GC problem, I edited the two eventListerners() in the Adobes’ fl.transitions.Tween so that their default weakReference property was false. Doing this made the Tween work correctly. But that’s a terrible solution.

Here’s my code. Its kinda stripped down just to show the setup.  
Thanks for helping me solve this one!

```php
package {

    import DataModel;
    import StackDisplay;
    import flash.display.*;
    import flash.events.*;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import fl.transitions.TweenEvent;

    public class Main extends MovieClip {
        
        private var _dataModel:DataModel;
        private var _stackDisplay:StackDisplay;
        private var _visibleAsset:uint;
        private var _timer:Timer;
        private var _timerTweenOut:Tween;
        private var _timerTweenIn:Tween;
        
        public function Main () {
            _dataModel = new DataModel();
            _stackDisplay = new StackDisplay(_dataModel, this);
            configureListeners ();
        }
        private function configureListeners ():void {
            _stackDisplay.addEventListener (Event.COMPLETE, initTimer, false, 0, true);
        }
        private function initTimer (evt:Event) {
            _timer = new Timer(1500);
            _timer.addEventListener (TimerEvent.TIMER, timerNext, false, 0, true);
            _timer.start ();

        }
        private function timerNext (evt:Event) {
                _timerTweenOut = new Tween(_stackDisplay.assetArray[_visibleAsset], "alpha", Regular.easeOut, 1, 0, 7, false);
                _visibleAsset++;
                _timerTweenIn = new Tween(_stackDisplay.assetArray[_visibleAsset], "alpha", None.easeOut, 0, 1, 7, false);
        }
    }
} 

```
