Specifications
61ADOBE FLEX 3
Building and Deploying Adobe Flex 3 Applications
Calculating memory usage
You use the totalMemory property in the System class to find out how much memory has been allocated to Flash
Player or AIR on the client. The
totalMemory property represents all the memory allocated to Flash Player or
AIR, not necessarily the memory being used by objects. Depending on the operating system, Flash Player or AIR
will be allocated more or less resources and will allocate memory with what is provided.
You can record the value of
totalMemory over time by using a Timer class to set up a recurring interval for the
timer event, and then listening for that event.
The following example displays the total amount of memory allocated (totmem) to Flash Player at 1-second
intervals. This value will increase and decrease. In addition, this example shows the maximum amount of memory
that had been allocated (maxmem) since the application started. This value will only increase.
<?xml version="1.0"?>
<!-- optimize/ShowTotalMemory.mxml -->
<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;
[Bindable]
public var maxmem:Number = 0;
public function initTimer():void {
// The first parameter is the interval (in milliseconds). The
// second parameter is number of times to run (0 means infinity).
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;
maxmem = Math.max(maxmem, totmem);
}
]]></mx:Script>
<mx:Form>
<mx:FormItem label="Time:">
<mx:Label text="{time} ms"/>










