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.

[as]
var mem:String = Number( System.totalMemory / 1024 / 1024 ).toFixed( 2 ) + ‘Mb’;
trace( mem ); // eg traces “24.94Mb”
[/as]

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.

Comments are closed.