9.0.115 버젼에서
flash.system.System.gc() 메소드가 추가되었다.
이 메소드의 작동 요건은
ADL(AIR 디버깅), installed application(설치된 AIR),
또는 content in application security sandbox 라고 하는데
이건 아마 로컬에서 실행되는 상태라고 이해할 수 있을거 같다.
기존의 가비지 컬렉터의 주기를 기다리지 말고
System.gc() 를 마음껏 날려주자.
GarbageCollector.mxml -
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()" viewSourceURL="srcview/index.html"> <mx:Script> <![CDATA[ import mx.core.UIComponent; private function init(): void { this.txtMemoryFirst.text = "first : " + ( int( System.totalMemory / 10 ) / 100 ).toFixed( 2 ) + " kb"; } private function create( e: MouseEvent ): void { var loop: int = e.ctrlKey ? 100 : 10; var shape: Shape; var ui: UIComponent; while( loop-- ) { shape = new Shape(); shape.graphics.beginFill( 0xFFCCBB, 0.3 ); shape.graphics.drawRoundRect( 0, 0, Math.random()*200 + 50, Math.random() * 200 + 50, 10, 10 ); shape.graphics.endFill(); shape.x = Math.random() * 100; shape.y = Math.random() * 70; ui = new UIComponent(); ui.addChild( shape ); this.canvas.addChild( ui ); } this.update(); } private function update(): void { var currentMemory: Number = int( System.totalMemory / 10 ) / 100; this.txtMemory.text = "current : " + currentMemory + " kb (" + ( currentMemory - this.lastMemory ).toFixed( 2 ) + " kb increased " + ( ( currentMemory - this.lastMemory ) / lastMemory ).toFixed( 2 ) + "%)"; } private var lastMemory: Number; public function onClear(): void { while( this.canvas.numChildren ) { var ui: UIComponent = this.canvas.getChildAt( 0 ) as UIComponent; ui.removeChild( ui.getChildAt( 0 ) ); this.canvas.removeChild( ui ); ui = null; } /* System.gc() - ADL(AIR Debug Launcher), 또는 installed Application (설치된 AIR), 또는 local 상의 swf 에서만 작동. */ System.gc(); this.lastMemory = int( System.totalMemory / 10 ) / 100; this.update(); this.txtMemoryLast.text = "last : " + this.lastMemory + " kb"; } ]]> </mx:Script> <mx:Canvas x="10" y="58" width="378" height="222" id="canvas"> </mx:Canvas> <mx:Text x="10" y="41" text="current : " width="378" id="txtMemory"/> <mx:Text x="10" y="25" text="last : " width="378" id="txtMemoryLast"/> <mx:Text x="10" y="9" text="Text" width="378" id="txtMemoryFirst"/> <mx:Button x="10" y="288" label="Create one more" id="btnCreate" click="create( event )"/> <mx:Button x="292" y="288" label="System.gc()" id="btnClear" click="onClear()"/> </mx:WindowedApplication>
| |
소스 다운로드 (air 파일 포함)