This application is a much simplified version of what I am trying to accomplish, some smoothing of some motion on the screen by using a composite animation and rerunning it as things change, and using bindings to set some of the values of the animation. The animation is periodically stopped, and then restarted. valueFrom is not set so a property value just continues from where it was towards a new goal. In this example, I’m animating a Rect’s left/top towards mouse’s X/Y to make it chase the mouse.
Problem is the memory of this application continues to grow if you wait a little while and continue to move the mouse. So what should I be doing that I am not?
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="creationCompleteHandler(event)"
mouseMove="mouseMoveHandler(event)"
mouseOut="mouseOutHandler(event)"
>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private static const RECT_HALF_SIZE:int = 5;
private static const NO_CHASE:int = -1000;
[Bindable]
private var lastMouseX:int = NO_CHASE;
[Bindable]
private var lastMouseY:int = NO_CHASE;
private var evalTimer:Timer = new Timer(100);
protected function creationCompleteHandler(event:FlexEvent):void
{
evalTimer.addEventListener(TimerEvent.TIMER, function(event:TimerEvent):void { evalChase(); });
evalTimer.start();
}
protected function mouseOutHandler(event:MouseEvent):void
{
lastMouseX = lastMouseY = NO_CHASE;
evalChase();
}
protected function mouseMoveHandler(event:MouseEvent):void
{
const reStart:Boolean = (lastMouseX == NO_CHASE);
lastMouseX = event.localX;
lastMouseY = event.localY;
if(reStart)
evalChase();
}
private function evalChase():void
{
doChase.stop();
doChase.end();
if(lastMouseX == NO_CHASE)
return;
doChase.play();
}
]]>
</fx:Script>
<fx:Declarations>
<s:Linear id="linearEaser" />
<s:Parallel
id="doChase"
duration="2000"
>
<s:Animate target="{chaser}" easer="{linearEaser}" >
<s:SimpleMotionPath property="left" valueTo="{lastMouseX-RECT_HALF_SIZE}" />
</s:Animate>
<s:Animate target="{chaser}" easer="{linearEaser}" >
<s:SimpleMotionPath property="top" valueTo="{lastMouseY-RECT_HALF_SIZE}" />
</s:Animate>
</s:Parallel>
</fx:Declarations>
<s:Rect
id="chaser"
top="0" left="0"
width="{2*RECT_HALF_SIZE}" height="{2*RECT_HALF_SIZE}"
>
<s:fill>
<s:SolidColor color="red" />
</s:fill>
</s:Rect>
</s:WindowedApplication>
Don’t think you’re actually doing anything wrong in this code, I copied into a new Flex 4.6 project and ran it, I could see what you’re saying with regard to the ADL process itself increasing slightly in memory consumption over time, particularly after it stops motion then begins again, however I tried running this in Flash Builder with the profiler and it seems the swf itself isn’t really leaking any memory, it stayed right around 1.1 MB for me (up to about 1.4, but then back down) it seems it had a fair amount of Vector.<*> objects in memory though I’m not clear on what is being stored in those objects.