Revision: 43730
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 30, 2011 00:31 by scottwatkins
Initial Code
// ******************************************************************************* // Garbage Collection // ******************************************************************************* private var gcTimer:Timer; public function creationCompleteHandler():void { startMemoryMonitoring(1000 * 60 * 30); } public function startMemoryMonitoring(garbageCollectEvery:Number):void { // Timer for garbage collection at regular intervals. Runs until the application exits. this.gcTimer = new Timer(garbageCollectEvery, 0); gcTimer.addEventListener(TimerEvent.TIMER, onTriggerGC); gcTimer.start(); } private function onTriggerGC(event:TimerEvent):void { trace("System Total Memory BEFORE Garbage Collection: " + System.totalMemory ); try { /** * Force garbage collection */ trace("Forcing Garbage Collection..."); new LocalConnection().connect('_noop'); new LocalConnection().connect('_noop'); } catch (e:Error) { // The following error is expected: Error #2082: Connect failed because the // object is already connected. Application.application.callLater(showTotalMemory); } } private function showTotalMemory():void { trace("System Total Memory AFTER Garbage Collection: " + System.totalMemory ); }
Initial URL
http://cookbooks.adobe.com/post_Garbage_Collection-18750.html
Initial Description
Initial Title
Garbage Collection
Initial Tags
Initial Language
ActionScript 3