AS3 MemoryMonitor


/ Published in: ActionScript 3
Save to your folder(s)

See how much RAM your SWF is using.

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


Copy this code and paste it in your HTML
  1. package
  2. {
  3. import flash.display.Sprite;
  4. import flash.text.TextField;
  5. import flash.events.TimerEvent;
  6. import flash.utils.Timer;
  7. import flash.system.System;
  8.  
  9. public class MemoryMonitor extends Sprite
  10. {
  11. private var memory_tf:TextField;
  12. private var myTimer:Timer;
  13. private var currMemory:Number;
  14.  
  15. public function MemoryMonitor():void
  16. {
  17. memory_tf = new TextField();
  18. memory_tf.border = true;
  19. memory_tf.width = 100;
  20. memory_tf.height = 20;
  21. currMemory = System.totalMemory;
  22.  
  23. myTimer = new Timer(0,0);
  24. myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
  25.  
  26. addChild(memory_tf);
  27. }
  28.  
  29. public function start(interval:Number):void
  30. {
  31. myTimer.delay = interval;
  32. myTimer.start();
  33. }
  34.  
  35. public function stop():void
  36. {
  37. myTimer.stop();
  38. }
  39.  
  40. public function get currentMemory():Number
  41. {
  42. return currMemory;
  43. }
  44.  
  45. private function timerHandler(evt:TimerEvent):void
  46. {
  47. currMemory = System.totalMemory;
  48. memory_tf.text = String((currMemory * 0.000000954).toFixed(3)) + " kb";
  49. }
  50.  
  51. }
  52. }
  53.  
  54. // USAGE EXAMPLE ...
  55. // var myMemMon = new MemoryMonitor();
  56. // addChild(myMemMon);
  57. // myMemMon.start(2000);

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.