I've created a custom Effect called "EndEffect" that when played will call
the end() method on the target effect sequence.

I've tested this code in both the Effect.initInstance() call of the Effect
and the EffectInstance.play() method:


        /**
         *  @private
         */
        override protected function
initInstance(instance:IEffectInstance):void
        {
            super.initInstance(instance);

            var targetEffect:IEffect = effect || target as IEffect;

            targetEffect.end();
            targetEffect = null;
        }

In my declarations I have this code:

            <c:EndEffect id="explicitEndSequence"
effect="{playerSequence}"/>

The effect that this effect targets (playerSequence) has an effect end
event listener like so:

        <s:Sequence id="player" effectEnd="trace('effect end')">
                ... it contains 3 child effects
        </s:Sequence>

With I play explicitEndSequence the console traces "effect end" 3 times:

effect end
effect end
effect end

Each subsequent calls it will show 3 more than the last (2nd call):

effect end
effect end
effect end
effect end
effect end
effect end

If I change the EndEffect code so that it doesn't create a local variable
it ends once correctly:

        /**
         *  @private
         */
        override protected function
initInstance(instance:IEffectInstance):void
        {
            super.initInstance(instance);

            effect.end(); // this works! Btw "effect" is a property on
EndEffect
        }

Why does the first code cause a memory leak and not delete the instances?

Reply via email to