Flash Memory Management (Ty)

Flash Player 9 has a powerful Virtual Machine that runs ActionScript 3 at speeds worthy of high-end applications while managing memory automatically. To help keep up that performance and minimize unused memory there are some basic principles to remember when building those applications.ActionScript 3 manages memory using a method called “mark and sweep”, which effectively removes data that isn’t referenced by any other part of the application. As long as all references to a piece of data are removed (pointers set to null or assigned to another piece of data) the data can be cleared and the memory freed. However there are often unnoticed references or “memory leaks” that can compound and eventually slow and crash any system. Following are the principles and techniques to keep in mind while building up Flex and Flash applications:

  • architect and code your application using good object oriented principles such as abstraction, composition, loose coupling, etc
  • identify the parts of the application that have frequent clearing of data (particularly DisplayObjects, these are often expensive in terms of memory)
  • identify and limit the number of references to a particular object (the principles of abstraction and “black box” strengthen your ability to limit these)
  • use weak referenced listeners and bindings everywhere that makes sense (if in question, use everywhere)
  • give objects that will be removed a cleanUp() method where they can remove listeners and clean up bindings
  • avoid listening or binding to objects outside of yourself except in manageable cases, such as a global data source
  • don’t use the Flex PopupManager

By following these principles and techniques you will be able to avoid most common memory problems. Flex has a built in profiler that will help you identify the remainder of memory and performance issues and help you know where to spend your time in optimization.Code responsibly.– Tyler

By: garyr Categories: flash / flex / memory

One Response to Flash Memory Management (Ty)

  1. Ellis Elkins says:

    Why not use the Flex PopupManager