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:
-
var mem:String = Number( System.totalMemory / 1024 / 1024 ).toFixed( 2 ) + 'Mb';
-
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
Leave a reply
[...] AS3.0 Memory monitoring » This Summary is from an article posted at pixelbreaker on Friday, November 09, 2007 I just [...]
Really useful! Thanks man!
thanks you.......
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.
no this has nothing to do with the debugger.
[...] Pixel Breaker has a good post that shows you how to convert bytes to Mega bytes. pixelbreaker : AS3.0 Memory monitoring [...]
thanks for all
This will come in handy when cleaning my bike.
But it is wrong.
You calculated MiB. If you want to know how
much MB you should divide twice throug 1000 and
NOT 1024 :)
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!
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.