AS3.0 Memory monitoring

I just came across the property System.totalMemory. It's very useful, especially for the engine I am currently working on, and dealing with AS3 garbage collection.

It returns the memory currently being used by the Flash Player. It's in bytes so it pays to clean it up slightly.

Actionscript:
  1. var mem:String = Number( System.totalMemory / 1024 / 1024 ).toFixed( 2 ) + 'Mb';
  2. trace( mem ); // eg traces "24.94Mb"

It seems this takes account of all instances of the flash player. For example, I have a logger/debug panel running in the sidebar of firefox, built in flex. As soon as I open this and it's initialised, it uses an extra 5 - 10mb of ram. So be warned, if you see a massive increase in memory usage, check you don't have loads of sites open with ad banners or other flash based stuff.

11 Comments so far

  1. [...] AS3.0 Memory monitoring » This Summary is from an article posted at pixelbreaker on Friday, November 09, 2007 I just [...]

  2. Simon / November 10th, 2007 11:12 am

    Really useful! Thanks man!

  3. aşk şiirleri / November 18th, 2007 5:26 pm

    thanks you.......

  4. sekati / December 14th, 2007 12:01 am

    Is this the same debugger you mentioned as your original post of the "kernel debugger"? You never did release this and I for one would love to see it in action/code.

  5. gabriel / December 17th, 2007 12:03 pm

    no this has nothing to do with the debugger.

  6. [...] Pixel Breaker has a good post that shows you how to convert bytes to Mega bytes. pixelbreaker : AS3.0 Memory monitoring [...]

  7. drcetinerdotorg / December 20th, 2007 2:17 pm

    thanks for all

  8. wheener / January 9th, 2008 5:49 pm

    This will come in handy when cleaning my bike.

  9. Timon / April 11th, 2008 1:15 pm

    But it is wrong.
    You calculated MiB. If you want to know how
    much MB you should divide twice throug 1000 and
    NOT 1024 :)

  10. Omar / April 14th, 2008 6:02 pm

    This is one of the shortest most useful snippets of code I've ever came around.

    As somebody mentioned there is a small inaccuracy in your code. You are indeed calculating megabyte which is expressed in short as MB, not Mb (megabits). I think that is what Timon is referring to.

    Keep up the good work and thanks for sharing!

  11. travesti / May 13th, 2008 12:39 pm

    this the same debugger you mentioned as your original post of the "kernel debugger"? You never did release this and I for one would love to see it in action/code.

Leave a reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image