moock.org is supported in part by


July 15, 2008

Things You Must Do Before Unloading a SWF File

If you load a .swf file into Flash Player 9 with ActionScript 3.0 and subsequently wish to remove it from memory, you must first deactivate it, and then dereference it. If you dereference the .swf without deactivating it, it will continue to consume resources and in some cases might never become eligible for garbage collection.

Here is an unofficial list of tasks required to deactivate a .swf file:

  • Tell any loaded .swf child assets to disable themselves.
  • Stop any sounds from playing.
  • Stop the main timeline, if it is currently playing.
  • Stop any movie clips that are currently playing.
  • Close any connected network objects, such as instances of Loader, URLLoader, Socket, XMLSocket, LocalConnection, NetConnections, and NetStream.
  • Release all references to cameras and microphones.
  • Unregister all event listeners in the .swf (particularly Event.ENTER_FRAME, and mouse and keyboard listeners)
  • Stop any currently running intervals (via clearInterval()).
  • Stop any Timer objects (via the Timer class’s instance method stop()).

Note that the preceding list is, by definition, insufficient because it is neither exhaustive nor officially maintained by Adobe. If you know of a task that needs adding to the preceding list, please sent it to me via email (username colin, domain moock.org).

As of Flash Player 10, the preceding tasks can be performed automatically by calling the Loader class's new method unloadAndStop().

For further discussion, see Charge #2 in my Inside RIA article, The Charges Against ActionScript 3.0 and Grant Skinner's article Additional Information on Loader.unloadAndStop().

Русский

Posted by moock at July 15, 2008 09:18 PM