How To Dynamically Clear Memory?

[COLOR=blue][FONT=Arial]The code below works but NOT properly. After few minutes, the flash animation slows down and also any other program that is running in the computer. I suspect that these routines flood the memory ( probably the stack memory because it uses recursion ) which then starts using slow virtual memory. [/FONT][/COLOR]

[COLOR=blue][FONT=Arial]There are two recursive processes initiated by two Timer types (Timer_1 and Timer_2 ) of addEventListener(). The functions that they call use a lot of “.draw()” and “.clone()” methods to manipulate memory-demanding bitmaps.[/FONT][/COLOR]

[COLOR=blue][FONT=Arial]For clarity sake I removed the lesser relevant part of the code.[/FONT][/COLOR]

[COLOR=blue][FONT=Arial]How to dynamically clean memory inside these routines and avoid them flooding computer’s RAM memory ?[/FONT][/COLOR]

[COLOR=blue][FONT=Arial]private function Animation( event:MouseEvent):void [/FONT][/COLOR]
[COLOR=blue][FONT=Arial]{[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] TargetClip.addChild(imgBg);[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] Clip_Area = TargetClip;[/FONT][/COLOR]
[COLOR=blue][FONT=Arial] Source_Clip = SourceClip;[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] SpecialEffect ();[/FONT][/COLOR]

[COLOR=blue][FONT=Arial]}[/FONT][/COLOR]

[COLOR=blue][FONT=Arial]private function SpecialEffect ():void[/FONT][/COLOR]
[COLOR=blue][FONT=Arial]{[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] ClonedMovieClip = new MovieClip();[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] Clip_Area.addChild(ClonedMovieClip);[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] var bitmapImage:BitmapData = new BitmapData(Source_Clip.width, Source_Clip.height, false, 0);[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] bitmapImage.draw(Source_Clip);[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] …[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] var Timer_1:Timer = new Timer(5); //new Timer(10);[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] Timer_1.addEventListener(‘timer’, turnOnEffect1);[/FONT][/COLOR]
[COLOR=blue][FONT=Arial] Timer_1.start();[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] var Timer_2:Timer = new Timer(150);[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] Timer_2.addEventListener(‘timer’, Effect2);[/FONT][/COLOR]
[COLOR=blue][FONT=Arial] Timer_2.start();[/FONT][/COLOR]
[COLOR=blue][FONT=Arial]}[/FONT][/COLOR]

[COLOR=blue][FONT=Arial]private function turnOnEffect1(ev:Object):void[/FONT][/COLOR]
[COLOR=blue][FONT=Arial]{[/FONT][/COLOR]
[COLOR=blue][FONT=Arial] var currentX = xPos / 2;[/FONT][/COLOR]
[COLOR=blue][FONT=Arial] var currentY = yPos / 2;[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] if ((Lasty != currentY) || (Lastx != currentX))[/FONT][/COLOR]
[COLOR=blue][FONT=Arial] {[/FONT][/COLOR]

[COLOR=blue][FONT=Arial]…[/FONT][/COLOR]
[COLOR=blue][FONT=Arial] OutputImage.applyFilter(Surface, new Rectangle(0, 0, Source_Clip.width, Source_Clip.height), Origin, Target);[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] Buffer = SourceBitmap;[/FONT][/COLOR]
[COLOR=blue][FONT=Arial] SourceBitmap = Bitmap1.clone();[/FONT][/COLOR]
[COLOR=blue][FONT=Arial] }[/FONT][/COLOR]
[COLOR=blue][FONT=Arial]}[/FONT][/COLOR]

[COLOR=blue][FONT=Arial]private function Effect2(ev:Object):void[/FONT][/COLOR]
[COLOR=blue][FONT=Arial]{[/FONT][/COLOR]

[COLOR=blue][FONT=Arial] }[/FONT][/COLOR]