AS3 Optimization


An AS3 module I was working on was eating up memory, and a FLVPlayback video was having some trouble playing occasionally, so I decided to track what was happening and systemically improve performance.


Searching the net I found a few good sites with information regarding memory optimization and general performance optimization:


(Mainly culled from the above list from Stuntman)

  • Use switch statements instead of a group of if/else statements. (better for performance)
  • Remove all listeners ( when no longer required ). This has had a dramatic positive effect in the performance of my Framework.
  • Make sure you stop and clear timers/intervals when not in use. (better for performance
  • Remove/Unload unneeded assets from the stage, when done with them. ( See add destroy() Methods
  • Use int instead of number when needed ( is better than uint, see above )
  • When exporting your Flash change the JPEG quality to 60. ( to check all over )
  • Allow the Garbage Collection to collect! to Quote from Krill: When storing references to methods what has to happen for garbage collection to act right is the objects involved must form a closed circuit. If there’s ANY reference to one of the objects in the circuit from outside then none of them will be garbage collected..

    The above information about to Method Closure relates to this.

  • Add destroy() Methods to Classes to remove assets and properties.


By following the techniques above systematically  I was able to improve performance dramatically. Now I will add weak referenced listeners as standard practice! Also, work on the idea of having a pair of create() and destroy() Methods in each relevant Class, to implement Lazy Loading and tidy asset removal.


One thought on “AS3 Optimization

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s