Flex获得使用内存数

《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>
此条目发表在 Flash 分类目录,贴了 , , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已被标记为 *

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>