《AdvancED Flex 3》中有一段讲述获得Flex运行时所占用的内存数,里面使用了一个系统属性:
flash.system.System.totalMemory
这个属性能够获得系统分给Flash Player的内存总数量,而不仅仅是此应用(application)所占用的内存数量。所以通过flash.system.System.totalMemory获得的数值会大于应用(application)所占用的内存数量。这里给出书中所举的例子:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="initTimer()">
<mx:Script>
<![CDATA[
import flash.utils.Timer;
import flash.events.TimerEvent;
[Bindable]
public var time:Number=0;
[Bindable]
public var totmem:Number=0;
public function initTimer():void{
var myTimer:Timer=new Timer(1000,0);
myTimer.addEventListener("timer",timerHandler);
myTimer.start();
}
public function timerHandler(event:TimerEvent):void{
time=getTimer();
totmem=flash.system.System.totalMemory;
}
]]>
</mx:Script>
<mx:Form>
<mx:FormItem label="Time:">
<mx:Label text="{time}" />
</mx:FormItem>
<mx:FormItem label="Total Memory:">
<mx:Label text="{totmem} bytes" />
</mx:FormItem>
</mx:Form>
</mx:Application>