I have an AS3 Flash app that successfully loads a very simple Flex app
into a movieClip contained in the Flash app. There's a button that
unloads it. And another that reloads the same Flex app.

Doing this load, unload, load causes the flash player memory to increase
the same amount upon each load. The Flex 3 profiler shows the instance
of the Flex app (and classes) loaded with a reference after the first
unload.

I've tried this with a new Application Domain context and without. I've
tried a Flex 3 app.

Is there something I'm missing? How can I get the Flex app to completely
unload, be de-referenced, and garbage collected?

The app can be found here (the textbox is just a display of Flash memory
usage)

http://www.gtechsoftware.net/tests/FlexLoaderMemoryTest.html
<http://www.gtechsoftware.net/tests/FlexLoaderMemoryTest.html>

Here is the code for the files:

FlexLoaderMemoryTest.fla - contains two button components w/ instance
names: loadFlexBtn and unloadBtn
AS3 publish settings : Automatically declare stage instances (unchecked)

Document class:

package {
     import flash.display.Loader;
     import flash.display.MovieClip;
     import flash.events.Event;
     import flash.events.MouseEvent;
     import flash.net.URLRequest;
     import flash.system.ApplicationDomain;
     import flash.system.LoaderContext;

     import fl.controls.Button;

     /**
      * @author Steve
      */
     public class FlexLoaderMemoryTest extends MovieClip {
         public var loadFlexBtn : Button;
         public var unloadBtn : Button;

         private var playArea_mc : MovieClip;
         private var loader : Loader;


         public function FlexLoaderMemoryTest() {
             addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
         }

         private function handleAddedToStage(event : Event) : void {
             createChildren();
             createLoader();
             setupUI();
         }

         private function createChildren() : void {
             playArea_mc = new MovieClip();
             playArea_mc.y = 100;
             addChild(playArea_mc);
         }

         private function setupUI():void{
             loadFlexBtn.addEventListener(MouseEvent.CLICK,
handleLoadFlexBtnClick);
             unloadBtn.addEventListener(MouseEvent.CLICK,
handleUnloadBtnClick);
         }

         private function handleLoadFlexBtnClick(event:MouseEvent) : void
{
             var context : LoaderContext = new LoaderContext();
             context.applicationDomain = new ApplicationDomain();

             loader.load(new URLRequest("testMemoryUsage.swf"), context);
         }

         private function handleUnloadBtnClick(event:MouseEvent) : void {
             loader.unload();
         }

         private function createLoader() : void {
             loader = new Loader();
             loader.y = 100;
             addChild(loader);
         }
     }
}

--------------------------------

testMemoryUsage.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
     layout="absolute"
     width="300" height="200"
     focusEnabled="false">
     <mx:Label text="This is a basic Flex swf w/ no listeners"/>
</mx:Application>


Reply via email to