Quick Tip: Monitor Memory and CPU in Your Applications

In this Quick Tip, we'll take a look at Hi-ReS! Stats: an easy way to display the FPS, memory usage and CPU usage of your Flash apps and games. Read on!


Step 1: Brief Overview

Hi-ReS! Stats for Flash and AS3

A third party ActionScript 3 class will be used to display the current amount of memory and cpu used by the Flash Player, this will make easier for the developer to detect memory or cpu leaks.


Step 2: Stats Class

Hi-ReS! Stats for Flash and AS3

The Hi-ReS! Stats class by Mr.Doob takes care of the job, you can download it on its GitHub page. You can also visit the blog post to read more about it.


Step 3: Usage

The usage couldn't be easier, just add the Stats.as class to your project folder and import it using the following code:

Then add this line in your constructor:

That's it, test your movie and you'll see a rectangle filled with the information in the top-left corner of your app.


Step 4: Example

I used the class in on the final SWF of my Space Shooter Tutorial game, it shows that memory stays between 5.5 and 6.5MB (Flash Player 10.2 Mac, Standalone) so that means there's no leak!


Conclusion

If you are a Flash Developer then the Stats class is a must try, it is simple, powerful and really useful.

Thank you for reading!

Tags:

Comments

Related Articles