2
votes

Consider an AIR application which can load any number of third-party SWF files one at a time for display. Like a Web Browser.

The problem is that these SWF files may have EventListeners which have not been removed, etc.

Will Loader.unloadAndStop() be enough to garbage collect these SWFs?

If not- is there an approach which will (maybe a new NativeWindow for each SWF, then close the NativeWindow when done. Will that completely GC?)

3
You could investigate overriding addEventListener to keep a list of the listeners. If objects are listening to the stage, you might have a hard time overriding the default stage instance with one of your own, however.Amy Blankenship

3 Answers

2
votes

Separate native window or loading inside a browser control can be a way for third party SWFs you have no control over. This adds a lot of overhead otherwise.

Unfortunately, you cannot ensure proper sandboxing of the loaded code (the display objects, most importantly, stage cannot be hidden from the loaded code). If the loaded code had added a listener to stage (which is a common thing to do if you need keyboard events), then it will not unload.

This is, however, impossible on mobile devices, where SWF format itself is different.

0
votes

A while back I had a similar issue with externally developed components to which we didn't have the source, and it was sandwiched into our application. The best I could do / think of, was to do what the nuclear industry does - when things go bad, at least contain it in concrete so it doesn't spread more than it has to.

My solution was to build a 'component pool' so that as the contaminated objects were requested to be "clean" they were put in a separate holding area to be reused when needed - this way only the minimum number needed were ever created during a running session.

-1
votes

You should make a public static function to remove all the listeners in the loaded swf file(s) before you GC it.