views:

142

answers:

1

So, I have an application where I'll be loading any number of swfs into a SWFLoader and removing them at runtime. The issue is - they are all timeline based movies authored in Flash CS3. I have very little control over what is in the movie other than the authors are not able to program any interactivity (i.e. no event listeners) but I want to make sure I am using the best technique to stop and trash these things so they don't hang around in memory too long. Here is the process I use right now to get rid of them:

  1. Try stopping the content using MovieClip(content).stop();
  2. Remove any listeners that I know about (ENTER_FRAME, etc...)
  3. Set the source of the SWFLoader to null.
  4. cross fingers, pray, make sacrifice (human if need be)

So that seems to work but is some better (or more comprehensive) method that you guys use to accomplish this same task? In all honesty - I'm not entirely sure these things aren't just kept in memory but I don't hear them so I don't know that they are there...

+2  A: 

Thats pretty much right. Loader (what SWFLoader uses under the hood), removes it's loaded clip from the stage with .unload(), but depending on what the clip has referenced the clip still runs and events still fire.

Flash Player 10 added .unloadAndStop(), but that is mostly just doing the same thing you are.

You could also try giving an explicit SecurityDomain (and probably ApplicationDomain so any contained classes are seperate as well) in the optional LoaderContext parameter to Loader.load(), to try to prevent it adding event listeners outside (if you don't trust the clip not to), and avoid forming any references to anything from the clip so it can be garbage collected - but apparantly it might still not unload in some cases.

Simon Buchan
Thats good stuff to know about the ApplicationDomain - thanks!
onekidney