ActionScript 3 垃圾收集

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 垃圾收集相关的知识,希望对你有一定的参考价值。

// *******************************************************************************
// 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 );
}

以上是关于ActionScript 3 垃圾收集的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 AS3装载机垃圾收集

在 AS3 中强制垃圾收集?

67.Java垃圾收集机制对象引用垃圾对象的判定垃圾收集算法标记—清除算法标记—整理算法分代收集垃圾收集器性能调优

JVM理论:(二/3)垃圾收集算法垃圾收集器

JVM之垃圾收集算法与垃圾收集器

Java虚拟机:GC算法和种类