/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// ******************************************************************************* // 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 ); }
URL: http://cookbooks.adobe.com/post_Garbage_Collection-18750.html