Return to Snippet

Revision: 24241
at February 24, 2010 06:51 by adrianparr


Updated Code
package
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.system.System;

	public class MemoryMonitor extends Sprite
	{
		private var memory_tf:TextField;
		private var myTimer:Timer;
		private var currMemory:Number;

		public function MemoryMonitor():void
		{
			memory_tf = new TextField();
			memory_tf.border = true;
			memory_tf.width = 100;
			memory_tf.height = 20;
			currMemory = System.totalMemory;
			
			myTimer = new Timer(0,0);			
			myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
			
			addChild(memory_tf);
		}
		
		public function start(interval:Number):void
		{
			myTimer.delay = interval;
			myTimer.start();
		}

		public function stop():void
		{
			myTimer.stop();
		}
		
		public function get currentMemory():Number
		{
			return currMemory;
		}
		
		private function timerHandler(evt:TimerEvent):void
		{
			currMemory = System.totalMemory;
			memory_tf.text = String((currMemory * 0.000000954).toFixed(3)) + " kb";
		}
		
	}
}

// USAGE EXAMPLE ...
// var myMemMon = new MemoryMonitor();
// addChild(myMemMon);
// myMemMon.start(2000);

Revision: 24240
at February 24, 2010 06:48 by adrianparr


Initial Code
package
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.system.System;
	public class MemoryMonitor extends Sprite
	{
		private var memory_tf:TextField;
		private var myTimer:Timer;
		private var currMemory:Number
		public function MemoryMonitor():void
		{
			memory_tf = new TextField();
			memory_tf.border=true
			memory_tf.width=100
			memory_tf.height=20
			currMemory = System.totalMemory;
			
			myTimer = new Timer(0,0);			
			myTimer.addEventListener(TimerEvent.TIMER, timerHandler)
			
			addChild(memory_tf)
			
		}
		
		public function start(interval:Number)
		{
			myTimer.delay=interval
			myTimer.start()
		}
		public function stop()
		{
			myTimer.stop()
		}
		
		public function get currentMemory():Number
		{
			return currMemory;
		}
		
		private function timerHandler(evt:TimerEvent):void
		{
			memory_tf.text = String((System.totalMemory * 0.000000954).toFixed(3)) + " kb";
		}
		
	}
}

// USAGE EXAMPLE ...
// var myMemMon = new MemoryMonitor();
// addChild(myMemMon);
// myMemMon.start(2000);

Initial URL
http://labs.adobe.com/downloads/flashplayer10.html

Initial Description
See how much RAM your SWF is using.

Alternatively, use Mr.doob's Stats.
http://code.google.com/p/mrdoob/wiki/stats

Initial Title
AS3 MemoryMonitor

Initial Tags


Initial Language
ActionScript 3