35 Replies Latest reply on Dec 2, 2010 7:01 AM by cosmacol

    Unload SWF File

    r.rubio

      Hi,

       

      I'm trying to develop a portal application.  I'm loading all swf files in a trusted sandbox configuration.

       

      When i unload the swf file as follows (note autoLoad set to true):

       

       

      swfLoader.source = null;

      swfLoader.validateNow();

       

       

      But when i run the profiler i notice that the application loaded on the swf file is never garbage collected (i.e. there is an instance for every time i load the swf file).

       

      When i look at what has references to the application i get the following:

       

      profiler.jpg

       

      Is there a standard method for removing reference to the application so that it is unloaded.  Currently my application is vanilla and contains nothing within the mxml.

        • 1. Re: Unload SWF File
          r.rubio Level 1

          I'm able to receive Event.UNLOAD from SwfLoader that loaded application.

           

          Does the application receive an event as a result of the Swf file that loaded it being unloaded?

           

          I tried Event.REMOVE and EVEN.REMOVED for Application with no success.

           

          I was going to try to clean up loaded application references there when the swf file is unloaded.

          • 2. Re: Unload SWF File
            Flex harUI Adobe Employee

            I would check for things hanging onto the systemManager.  Although I thought

            if you got UNLOAD it was actually unloading.

            • 3. Re: Unload SWF File
              r.rubio Level 1

              Yes.  I get Unload but it does not unload.

               

              I do see the system manager containing references as shown on the profiler picture attached.

               

              My question is do i need to keep system manager of loaded application in a member variable in my portal application or is there some event that contains this system manager.

               

              The Unload event contains a reference to the SWFLoader but the content is null since the application has been unloaded and i did not see a preUnload.

              • 4. Re: Unload SWF File
                r.rubio Level 1

                Hi, I've attached two images.  One image shows the depenency list for the loaded application the other for the system manager associated with the application.

                 

                I'm stuck as to what i need to do to get application and system manager to get garbage collected.  The application is vanilla in that its just an empty mxml.

                 

                Thanks.

                 

                System Manager Image

                 

                profilerSystemManager.jpg

                 

                Applicaiton image:

                profilerApplication.jpg

                • 5. Re: Unload SWF File
                  Flex harUI Adobe Employee

                  I'm not clear on what parameters you are using to load.  I'd read the posts

                  on unloading modules on my blog as most of those issues will pertain to

                  subapps

                   

                  --

                  Alex Harui

                  Flex SDK Team

                  Adobe System, Inc.

                  http://blogs.adobe.com/aharui

                  • 6. Re: Unload SWF File
                    r.rubio Level 1

                    hi alex,

                    using flex sdk 3.5

                     

                    loaded application as sibling with bootstrap as follows:

                     

                    var loaderContext:LoaderContext = new LoaderContext();

                    loaderContext.securityDomain = SecurityDomain.currentDomain;

                    loaderContext.applicationDomain = new ApplicationDomain(bootStrapAppDomain);

                     

                    var swfLoader:SWFLoader = new SWFLoader();

                    swfLoader.autoLoad = false;

                    swfLoader.loaderContext = loaderContext_p;

                     

                    unload logic is to call:

                    swfLoader.addEventListener(Event.UNLOAD, unloadSwfHandler);

                    swfLoader.unloadAndStop(true);

                     

                    unloadSwfHandler is called when unloadAndStop is called but i never see [UnloadSWF] message on debug console.

                     

                    I do not know how to remove the remaining dependencies shown in the images.  I also added code in during unload swf process to remove all children from system manager using removeChildAt method but profiler still shows system manager contains pointer to loaded child application.

                     

                    For example the following systemManager is shown to contain a reference to the main application by the profiler.

                     

                    instance = systemManager

                    property = http://www.adobe.com/2006/flex/mx/internal:topLevelWindow

                     

                    How do i clear this?

                    • 7. Re: Unload SWF File
                      r.rubio Level 1

                      More info...  Dont know if it helps or not but i'm able to unload the swf file with no issues when i use a flat space (i.e. load swf file as a module in same security domain and application domain as parent application).

                       

                      But when i use sandbox with bootstrap [Unload SWF] message is never seen.

                      • 8. Re: Unload SWF File
                        Flex harUI Adobe Employee

                        Check for references from the bootstrap to the swf.  If the SWF is listening

                        for events from the bootstrap, that could be trouble.

                        • 9. Re: Unload SWF File
                          Flex harUI Adobe Employee

                          That systemManager should be the systemManger of the sub-app and can't be

                          the source of the leak.  Usually it is references to the systemManager that

                          keep the whole thing in memory.

                          • 10. Re: Unload SWF File
                            learner_doug Level 1

                            Not sure if this will help your situation, but I had to use loader.unloadAndStop(); after loading an external swf with the SWFloader to get the SWF to actually unload.

                            • 11. Re: Unload SWF File
                              r.rubio Level 1

                              No references from swf to bootstrap SystemManager that i can tell.

                               

                              The bootstrap code is the one provided in loading_application.pdf provided by Adobe.  No references to sub-app system manager there.

                               

                              profiler shows that mx.managers:SystemChildrenList:owner has a reference to sub-app system manager.

                               

                              How is this reference cleared?

                              • 12. Re: Unload SWF File
                                Flex harUI Adobe Employee

                                SystemChildrenList should be self-contained and probably not the cause of a

                                leak.

                                 

                                What does the bootstrap loader code look like?

                                • 13. Re: Unload SWF File
                                  r.rubio Level 1

                                  Here is the reference list for the system manager.  The boot strap code is shown below that.

                                  siblingSystemManagerReferenceList.jpg

                                  As you can see swf file was loaded three times and there are three references of same system manager even though unload is called.  I've also expanded the list of references that contain a reference to system manager.

                                   

                                  I do not know how to clear any of them and not sure why system manager is not being released.

                                   

                                  Here is the bootstrap code.

                                   

                                   

                                  public class main extends Sprite {

                                   

                                  public function main() {

                                  super();

                                   

                                  if (ApplicationDomain.currentDomain.hasDefinition("mx.core::UIComponent"))

                                  throw new Error("UIComponent should not be in the bootstrap loader.");

                                  /*    if (ApplicationDomain.currentDomain.hasDefinition("mx.core::Singleton"))

                                  throw new Error("Signleton should not be in the bootstrap loader.");   */

                                   

                                  if (stage) {

                                  stage.scaleMode = StageScaleMode.NO_SCALE;

                                  stage.align = StageAlign.TOP_LEFT;

                                  } else {

                                  isStageRoot = false;

                                  }

                                  root.loaderInfo.addEventListener(Event.INIT, onInit);

                                  }

                                   

                                  /**

                                  * The Loader that loads the main application's SWF file.

                                  */

                                  private var loader:Loader;

                                   

                                  /**

                                  * Whether the bootstrap loader is at the stage root or not.

                                  * It is only the stage root if it was the root

                                  * of the first SWF file that was loaded by Flash Player.

                                  * Otherwise, it could be a top-level application but not stage root

                                  * if it was loaded by some other non-Flex shell or is sandboxed.

                                  */

                                  private var isStageRoot:Boolean = true;

                                   

                                  /**

                                  * Called when the bootstrap loader's SWF file has been loaded.

                                  * Starts loading the application SWF specified by the applicationURL property.

                                  */

                                  private function onInit(event:Event):void {

                                  loader = new Loader();

                                   

                                  var currentAppDomain:ApplicationDomain = ApplicationDomain.currentDomain;

                                   

                                  var loaderContext:LoaderContext  = new LoaderContext(

                                     false,

                                     new ApplicationDomain(currentAppDomain),

                                     SecurityDomain.currentDomain

                                  );

                                   

                                  addChild(loader);

                                  loader.load(new URLRequest("/unithru/client/uiportal.swf"), loaderContext);

                                   

                                  loader.addEventListener(

                                  "mx.managers.SystemManager.isBootstrapRoot",

                                  bootstrapRootHandler

                                  );

                                  loader.addEventListener(

                                  "mx.managers.SystemManager.isStageRoot",

                                  stageRootHandler

                                  );

                                   

                                  loader.addEventListener(Event.ADDED, resizeHandler );

                                  stage.addEventListener(Event.RESIZE, resizeHandler);

                                  }

                                   

                                  private function bootstrapRootHandler(event:Event):void {

                                  event.preventDefault();

                                  }

                                   

                                  private function stageRootHandler(event:Event):void {

                                  if (!isStageRoot)

                                  event.preventDefault();

                                  }

                                   

                                  private function resizeHandler(event:Event=null):void {

                                  if ( loader.content ){

                                  Object(loader.content).setActualSize(stage.stageWidth, stage.stageHeight);

                                  }

                                  }

                                    }

                                  }

                                  • 14. Re: Unload SWF File
                                    Flex harUI Adobe Employee

                                    I guess I also need to see how you are loading the sub-apps that aren't

                                    unloading.

                                     

                                    I would also examine the EventProxy and see what is holding onto it.

                                    • 15. Re: Unload SWF File
                                      r.rubio Level 1

                                      Hi Alex,

                                       

                                      Attached is image showing eventProxy is held by same systemManager that eventProxy references (same ID 105150) .

                                       

                                      profilerSystemManager.jpg

                                       

                                      Swf files are loaded as follows:

                                       

                                      var loaderContext:LoaderContext = new LoaderContext();

                                      loaderContext.securityDomain = SecurityDomain.currentDomain;

                                      loaderContext.applicationDomain = new ApplicationDomain(bootStrapAppDomain);

                                       

                                       

                                      var swfLoader:SWFLoader = new SWFLoader();

                                      swfLoader.autoLoad = false;

                                      swfLoader.loaderContext = loaderContext;

                                       

                                      swfLoader.load(url);

                                       

                                       

                                      unload logic is to call:

                                       

                                      swfLoader.addEventListener(Event.UNLOAD, unloadSwfHandler);

                                      swfLoader.unloadAndStop(true);

                                      • 16. Re: Unload SWF File
                                        Flex harUI Adobe Employee

                                        Going back over the old profiler data, I see a ref to the Application from

                                        com.samsung.....

                                         

                                        What is that?  Make sure you are really vanilla.  No custom classes, only MX

                                        classes.

                                        • 17. Re: Unload SWF File
                                          r.rubio Level 1

                                          Hi Alex,

                                           

                                          Yes i removed those.  Now truly vanilla as u can see from latest profiler stack trace.

                                          • 18. Re: Unload SWF File
                                            Flex harUI Adobe Employee

                                            How about generating a link-report for the bootstrap?  Let's see what

                                            classes are in there.  Maybe one of them has a reference to something in the

                                            sub-app.

                                            • 19. Re: Unload SWF File
                                              r.rubio Level 1

                                              Here it is.  Did not see anything out of ordinary.

                                               

                                              <report>
                                                <scripts>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/core/IUIComponent)" mod="1259075989629" size="4563" optimizedsize="1152">
                                                    <def id="mx.core:IUIComponent" />
                                                    <pre id="Object" />
                                                    <pre id="mx.core:IFlexDisplayObject" />
                                                    <dep id="mx.managers:ISystemManager" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.display:DisplayObjectContainer" />
                                                    <dep id="flash.display:DisplayObject" />
                                                    <dep id="flash.display:Sprite" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/utils/RPCObjectUtil)" mod="1259075940689" size="7130" optimizedsize="5264">
                                                    <def id="mx.utils:RPCObjectUtil" />
                                                    <pre id="Object" />
                                                    <dep id="flash.utils:describeType" />
                                                    <dep id="flash.utils:getQualifiedClassName" />
                                                    <dep id="Date" />
                                                    <dep id="AS3" />
                                                    <dep id="QName" />
                                                    <dep id="flash.xml:XMLNode" />
                                                    <dep id="XML" />
                                                    <dep id="mx.core:mx_internal" />
                                                    <dep id="XMLList" />
                                                    <dep id="flash.utils:Dictionary" />
                                                    <dep id="Error" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/core/IChildList)" mod="1259075989520" size="1480" optimizedsize="497">
                                                    <def id="mx.core:IChildList" />
                                                    <pre id="Object" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.display:DisplayObject" />
                                                    <dep id="flash.geom:Point" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/config/ConfigMap)" mod="1259075949283" size="2285" optimizedsize="1019">
                                                    <def id="mx.messaging.config:ConfigMap" />
                                                    <pre id="flash.utils:Proxy" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.utils:flash_proxy" />
                                                    <dep id="mx.utils:object_proxy" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/utils/RPCUIDUtil)" mod="1259075940689" size="2858" optimizedsize="1848">
                                                    <def id="mx.utils:RPCUIDUtil" />
                                                    <pre id="Object" />
                                                    <dep id="Date" />
                                                    <dep id="flash.utils:ByteArray" />
                                                    <dep id="AS3" />
                                                    <dep id="Math" />
                                                    <dep id="mx.core:mx_internal" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/core/IButton)" mod="1259075988989" size="642" optimizedsize="230">
                                                    <def id="mx.core:IButton" />
                                                    <pre id="mx.core:IUIComponent" />
                                                    <pre id="Object" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/managers/IFocusManager)" mod="1259075991942" size="2728" optimizedsize="773">
                                                    <def id="mx.managers:IFocusManager" />
                                                    <pre id="Object" />
                                                    <dep id="mx.core:IButton" />
                                                    <dep id="mx.managers:IFocusManagerComponent" />
                                                    <dep id="flash.events:IEventDispatcher" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.display:InteractiveObject" />
                                                    <dep id="flash.display:DisplayObject" />
                                                    <dep id="flash.display:Sprite" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/IMessage)" mod="1259075949565" size="1995" optimizedsize="409">
                                                    <def id="mx.messaging.messages:IMessage" />
                                                    <pre id="Object" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/RemotingMessage)" mod="1259075949830" size="654" optimizedsize="264">
                                                    <def id="mx.messaging.messages:RemotingMessage" />
                                                    <pre id="mx.messaging.messages:AbstractMessage" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/core/mx_internal)" mod="1259075988989" size="190" optimizedsize="109">
                                                    <def id="mx.core:mx_internal" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/core/IFlexDisplayObject)" mod="1259075989661" size="6251" optimizedsize="1339">
                                                    <def id="mx.core:IFlexDisplayObject" />
                                                    <pre id="flash.events:IEventDispatcher" />
                                                    <pre id="flash.display:IBitmapDrawable" />
                                                    <pre id="Object" />
                                                    <dep id="flash.accessibility:AccessibilityProperties" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.display:DisplayObjectContainer" />
                                                    <dep id="flash.geom:Rectangle" />
                                                    <dep id="flash.display:DisplayObject" />
                                                    <dep id="flash.display:Stage" />
                                                    <dep id="flash.display:LoaderInfo" />
                                                    <dep id="flash.geom:Point" />
                                                    <dep id="flash.geom:Transform" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/ISmallMessage)" mod="1259075949815" size="571" optimizedsize="196">
                                                    <def id="mx.messaging.messages:ISmallMessage" />
                                                    <pre id="Object" />
                                                    <pre id="mx.messaging.messages:IMessage" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Source\Core\unithru_core_client_loader_flex\src\main.as" mod="1285282178028" size="2225" optimizedsize="1525">
                                                    <def id="main" />
                                                    <pre id="flash.display:Sprite" />
                                                    <dep id="flash.display:StageScaleMode" />
                                                    <dep id="flash.events:Event" />
                                                    <dep id="mx.messaging.messages:MessagePerformanceInfo" />
                                                    <dep id="mx.messaging.messages:HTTPRequestMessage" />
                                                    <dep id="mx.messaging.messages:AcknowledgeMessage" />
                                                    <dep id="flash.net:URLRequest" />
                                                    <dep id="mx.messaging.messages:CommandMessage" />
                                                    <dep id="flash.display:Loader" />
                                                    <dep id="flash.system:ApplicationDomain" />
                                                    <dep id="Error" />
                                                    <dep id="mx.messaging.messages:SOAPMessage" />
                                                    <dep id="mx.messaging.messages:AsyncMessageExt" />
                                                    <dep id="flash.system:SecurityDomain" />
                                                    <dep id="mx.managers:ISystemManager" />
                                                    <dep id="mx.messaging.messages:RemotingMessage" />
                                                    <dep id="mx.messaging.messages:AcknowledgeMessageExt" />
                                                    <dep id="AS3" />
                                                    <dep id="mx.messaging.config:ConfigMap" />
                                                    <dep id="mx.events:FlexEvent" />
                                                    <dep id="mx.messaging.messages:ErrorMessage" />
                                                    <dep id="flash.system:LoaderContext" />
                                                    <dep id="mx.messaging.messages:AsyncMessage" />
                                                    <dep id="flash.display:StageAlign" />
                                                    <dep id="mx.messaging.messages:CommandMessageExt" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/managers/ISystemManager)" mod="1259075991958" size="4795" optimizedsize="1386">
                                                    <def id="mx.managers:ISystemManager" />
                                                    <pre id="mx.core:IFlexModuleFactory" />
                                                    <pre id="flash.events:IEventDispatcher" />
                                                    <pre id="mx.core:IChildList" />
                                                    <pre id="Object" />
                                                    <dep id="flash.events:Event" />
                                                    <dep id="mx.managers:IFocusManagerContainer" />
                                                    <dep id="flash.text:TextFormat" />
                                                    <dep id="AS3" />
                                                    <dep id="mx.core:ISWFBridgeGroup" />
                                                    <dep id="flash.geom:Rectangle" />
                                                    <dep id="flash.display:DisplayObject" />
                                                    <dep id="flash.display:Stage" />
                                                    <dep id="flash.display:LoaderInfo" />
                                                    <dep id="flash.display:Sprite" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/core/IFlexModuleFactory)" mod="1259075988973" size="976" optimizedsize="297">
                                                    <def id="mx.core:IFlexModuleFactory" />
                                                    <pre id="Object" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.utils:Dictionary" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/SOAPMessage)" mod="1259075949815" size="1271" optimizedsize="699">
                                                    <def id="mx.messaging.messages:SOAPMessage" />
                                                    <pre id="mx.messaging.messages:HTTPRequestMessage" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/core/ISWFBridgeGroup)" mod="1259075989676" size="1224" optimizedsize="397">
                                                    <def id="mx.core:ISWFBridgeGroup" />
                                                    <pre id="Object" />
                                                    <dep id="flash.events:IEventDispatcher" />
                                                    <dep id="AS3" />
                                                    <dep id="mx.core:ISWFBridgeProvider" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/events/FlexEvent)" mod="1259076013693" size="2417" optimizedsize="1480">
                                                    <def id="mx.events:FlexEvent" />
                                                    <pre id="flash.events:Event" />
                                                    <dep id="AS3" />
                                                    <dep id="mx.core:mx_internal" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\framework.swc(mx/utils/object_proxy)" mod="1259075999614" size="208" optimizedsize="125">
                                                    <def id="mx.utils:object_proxy" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/ErrorMessage)" mod="1259075949565" size="1063" optimizedsize="541">
                                                    <def id="mx.messaging.messages:ErrorMessage" />
                                                    <pre id="mx.messaging.messages:AcknowledgeMessage" />
                                                    <dep id="AS3" />
                                                    <dep id="mx.messaging.messages:IMessage" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/core/ISWFBridgeProvider)" mod="1259075989676" size="785" optimizedsize="263">
                                                    <def id="mx.core:ISWFBridgeProvider" />
                                                    <pre id="Object" />
                                                    <dep id="flash.events:IEventDispatcher" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/CommandMessageExt)" mod="1259075949799" size="1008" optimizedsize="464">
                                                    <def id="mx.messaging.messages:CommandMessageExt" />
                                                    <pre id="mx.messaging.messages:CommandMessage" />
                                                    <pre id="flash.utils:IExternalizable" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.utils:IDataOutput" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/HTTPRequestMessage)" mod="1259075949565" size="1757" optimizedsize="880">
                                                    <def id="mx.messaging.messages:HTTPRequestMessage" />
                                                    <pre id="mx.messaging.messages:AbstractMessage" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/CommandMessage)" mod="1259075949799" size="4385" optimizedsize="2638">
                                                    <def id="mx.messaging.messages:CommandMessage" />
                                                    <pre id="mx.messaging.messages:AsyncMessage" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.utils:IDataOutput" />
                                                    <dep id="flash.utils:IDataInput" />
                                                    <dep id="mx.messaging.messages:IMessage" />
                                                    <dep id="mx.messaging.messages:CommandMessageExt" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/AcknowledgeMessage)" mod="1259075949815" size="1725" optimizedsize="938">
                                                    <def id="mx.messaging.messages:AcknowledgeMessage" />
                                                    <pre id="mx.messaging.messages:ISmallMessage" />
                                                    <pre id="mx.messaging.messages:AsyncMessage" />
                                                    <dep id="mx.messaging.messages:AcknowledgeMessageExt" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.utils:IDataOutput" />
                                                    <dep id="flash.utils:IDataInput" />
                                                    <dep id="mx.messaging.messages:IMessage" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/AsyncMessage)" mod="1259075949799" size="2629" optimizedsize="1411">
                                                    <def id="mx.messaging.messages:AsyncMessage" />
                                                    <pre id="mx.messaging.messages:ISmallMessage" />
                                                    <pre id="mx.messaging.messages:AbstractMessage" />
                                                    <dep id="mx.messaging.messages:AsyncMessageExt" />
                                                    <dep id="flash.utils:ByteArray" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.utils:IDataOutput" />
                                                    <dep id="flash.utils:IDataInput" />
                                                    <dep id="mx.messaging.messages:IMessage" />
                                                    <dep id="mx.utils:RPCUIDUtil" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/utils/RPCStringUtil)" mod="1259075940689" size="1722" optimizedsize="959">
                                                    <def id="mx.utils:RPCStringUtil" />
                                                    <pre id="Object" />
                                                    <dep id="AS3" />
                                                    <dep id="mx.core:mx_internal" />
                                                    <dep id="RegExp" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/managers/IFocusManagerComponent)" mod="1259075999302" size="1320" optimizedsize="326">
                                                    <def id="mx.managers:IFocusManagerComponent" />
                                                    <pre id="Object" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/MessagePerformanceInfo)" mod="1259075949799" size="1491" optimizedsize="730">
                                                    <def id="mx.messaging.messages:MessagePerformanceInfo" />
                                                    <pre id="Object" />
                                                    <dep id="Date" />
                                                    <dep id="AS3" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/AcknowledgeMessageExt)" mod="1259075949815" size="1044" optimizedsize="476">
                                                    <def id="mx.messaging.messages:AcknowledgeMessageExt" />
                                                    <pre id="mx.messaging.messages:AcknowledgeMessage" />
                                                    <pre id="flash.utils:IExternalizable" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.utils:IDataOutput" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/AbstractMessage)" mod="1259075949815" size="6545" optimizedsize="3334">
                                                    <def id="mx.messaging.messages:AbstractMessage" />
                                                    <pre id="Object" />
                                                    <pre id="mx.messaging.messages:IMessage" />
                                                    <dep id="mx.utils:RPCObjectUtil" />
                                                    <dep id="flash.utils:getQualifiedClassName" />
                                                    <dep id="flash.utils:ByteArray" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.utils:IDataOutput" />
                                                    <dep id="mx.core:mx_internal" />
                                                    <dep id="flash.utils:IDataInput" />
                                                    <dep id="mx.utils:RPCStringUtil" />
                                                    <dep id="mx.utils:RPCUIDUtil" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\rpc.swc(mx/messaging/messages/AsyncMessageExt)" mod="1259075949799" size="968" optimizedsize="438">
                                                    <def id="mx.messaging.messages:AsyncMessageExt" />
                                                    <pre id="flash.utils:IExternalizable" />
                                                    <pre id="mx.messaging.messages:AsyncMessage" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.utils:IDataOutput" />
                                                  </script>
                                                  <script name="C:\work\sisa\snapshot\cc\unithru_rrubio_view\UniThru\Tools\FlexSDK3.5\3.5.0\frameworks\libs\flex.swc(mx/managers/IFocusManagerContainer)" mod="1259075999286" size="1056" optimizedsize="358">
                                                    <def id="mx.managers:IFocusManagerContainer" />
                                                    <pre id="flash.events:IEventDispatcher" />
                                                    <pre id="Object" />
                                                    <dep id="mx.managers:ISystemManager" />
                                                    <dep id="AS3" />
                                                    <dep id="flash.display:DisplayObject" />
                                                    <dep id="mx.managers:IFocusManager" />
                                                  </script>
                                                </scripts>
                                                <external-defs>
                                                  <ext id="flash.utils:ByteArray" />
                                                  <ext id="Math" />
                                                  <ext id="RegExp" />
                                                  <ext id="flash.system:ApplicationDomain" />
                                                  <ext id="flash.display:StageAlign" />
                                                  <ext id="XMLList" />
                                                  <ext id="flash.events:Event" />
                                                  <ext id="AS3" />
                                                  <ext id="flash.utils:describeType" />
                                                  <ext id="flash.net:URLRequest" />
                                                  <ext id="flash.utils:IDataOutput" />
                                                  <ext id="XML" />
                                                  <ext id="flash.display:InteractiveObject" />
                                                  <ext id="flash.display:LoaderInfo" />
                                                  <ext id="flash.events:IEventDispatcher" />
                                                  <ext id="flash.geom:Rectangle" />
                                                  <ext id="QName" />
                                                  <ext id="flash.utils:Dictionary" />
                                                  <ext id="Error" />
                                                  <ext id="flash.system:SecurityDomain" />
                                                  <ext id="flash.display:IBitmapDrawable" />
                                                  <ext id="Date" />
                                                  <ext id="flash.display:DisplayObject" />
                                                  <ext id="flash.accessibility:AccessibilityProperties" />
                                                  <ext id="Object" />
                                                  <ext id="flash.utils:IDataInput" />
                                                  <ext id="flash.utils:flash_proxy" />
                                                  <ext id="flash.display:DisplayObjectContainer" />
                                                  <ext id="flash.text:TextFormat" />
                                                  <ext id="flash.xml:XMLNode" />
                                                  <ext id="flash.utils:IExternalizable" />
                                                  <ext id="flash.display:Sprite" />
                                                  <ext id="flash.display:Loader" />
                                                  <ext id="flash.utils:Proxy" />
                                                  <ext id="flash.geom:Point" />
                                                  <ext id="flash.display:Stage" />
                                                  <ext id="flash.system:LoaderContext" />
                                                  <ext id="flash.geom:Transform" />
                                                  <ext id="flash.utils:getQualifiedClassName" />
                                                  <ext id="flash.display:StageScaleMode" />
                                                </external-defs>
                                              </report>
                                              
                                               
                                              

                                              • 20. Re: Unload SWF File
                                                Flex harUI Adobe Employee

                                                What player version are you using?  10.1 is supposed to eliminate the need

                                                for bootstrap configurations.

                                                 

                                                Is your sub-app truly empty now?  Just an mx:Application tag?

                                                 

                                                Have you forced garbage collection after the unload event?

                                                • 21. Re: Unload SWF File
                                                  r.rubio Level 1

                                                  Using version 10.1 but it seems i still need boostrap as i get type coercion errors when sharing common data types across application domains (from portal -> application).

                                                   

                                                  I was finally able to see some Unload SWF messages.  There is still an issue as i dont know why it sometimes releases and sometimes does not.

                                                   

                                                  I do run the garbage collector after each load but right now i run 5 loads and it only releases 1.

                                                   

                                                  Any idea why?

                                                  • 22. Re: Unload SWF File
                                                    Flex harUI Adobe Employee

                                                    GC in 10.1 has some odd behavior.  But as long as you are getting unload swf

                                                    messages you are good to go.

                                                    • 23. Re: Unload SWF File
                                                      cosmacol Level 1

                                                      Hi,

                                                       

                                                      I'm trying to accomplish the same thing: loading an external application downloading the swf bytecode, being able to correctly unload it later.

                                                       

                                                      I found the exact same problem described here: the instances in the child ApplicationDomain are never garbage collected, and the SystemManager of the child Flex application is held along with a lot of other references (such as CSS style declarations, drag manager, and other stuff).

                                                       

                                                      I tried to load a competely empty application as suggested - just an empty <mx:Application> object, compiled with the Flex 3.5.0 SDK, in an AIR application compiled with the Flex 3.5.0 SDK overhauled with the 2.0 AIR SDK. The loaded Flex SWF is compiled for release.

                                                       

                                                      The loading method is pretty much the one described by r.rubio: a Loader object, with a LoaderContext to allow code import and place the loaded definitions in a new ApplicationDomain, child of the root one. I create a new standard NativeWindow and add the Loader to its stage. Then, I unload the SWF removing the Loader from the display list, calling unloadAndStop() on it, and freeing in the bootstrap application any reference and listener to the Loader object itself, to the LoaderContext, to the NativeWindow that was holding it, to the ApplicationDomain object, etc. etc.

                                                       

                                                      The behavior I get is exactly the same described by Conrad Winchester in his blog post It Is Impossible To Unload A Flex Application! (http://www.dz015.com/?p=166) - I see 35 references from the GC Root to the main Flex Application class, and it is *always* held by its generated SystemManager class (_Main_mx_managers_SystemManager, since my application is named Main.mxml).

                                                       

                                                      The SystemManager, in turn, is held in various way:

                                                       

                                                      • 29 out of 35 references are due to a lot of Object instances, considered as GC Roots, with a property named fbs referring the system manager - the mentioned post explains these as closure issues created during the application initialization by the "mixins" - see the post for further details.
                                                      • The static lastSystemManager property of the SystemManager class.
                                                      • 3 paths seem almost equivalent: the callLaterObject property a the LayoutManager instance (that is held by the Singleton class and by UIComponentGlobals) refers to an UIComponent that holds its _systemManager.
                                                      • The topLevelSystemManagers static property of SystemManagerGlobals class.
                                                      • The application static property of ApplicationGlobals class.

                                                       

                                                       

                                                      The closure issues described in the first point actually seems to be bugs, that could be fixed in the vm templates used by MXMLC (see the post). All the other paths, on the other hand, are related to static class properties. So, how does the garbage collector manages the static class properties, when the class definitions belong to a child ApplicationDomain? Are they supposed to be marked for collection someway when the class definition itself is not referenced outside of its domain and all the instances are eligible for gargabe collection? Should the unloadAndStop() method deal with them?

                                                       

                                                      Thank you

                                                       

                                                      Cosma

                                                      • 24. Re: Unload SWF File
                                                        learner_doug Level 1

                                                        Thanks Cosma, every piece of information helps.  I didn't realize how big an issue this was.

                                                         

                                                        Best,

                                                        Doug

                                                        • 25. Re: Unload SWF File
                                                          Flex harUI Adobe Employee

                                                          UnloadAndStop does not break actionscript references.  Statics are just

                                                          another set of references from the classes in the appdom to other things.

                                                          The appdom is held in place by a reference from the SWF that is removed via

                                                          calls to unload or unloadAndStop, and by instances of classes that still

                                                          exist.  Once there are no paths from the GC root to the classes in the

                                                          appdom, the whole thing should go away, even if there are internal

                                                          references between classes in the appdom and instances of those classes.

                                                           

                                                          The fbs references can generally be ignored.  I have yet to see them cause a

                                                          problem.

                                                           

                                                          I am currently investigating an AIR2.0 unloading problem.  I'll report back

                                                          when I've completed the investigation.

                                                          • 26. Re: Unload SWF File
                                                            r.rubio Level 1

                                                            Alex,

                                                             

                                                            Is there some cleanup that needs to happen when remote calls are made within the sandboxed application?

                                                             

                                                            Currently i'm able to unload my sandboxed application but when i add a remote call the swf file is never unloaded.

                                                             

                                                            Remote call is being made through an AMF channel.  If i simply comment the remote call the swf file is unloaded.

                                                             

                                                            Any ideas?

                                                            • 27. Re: Unload SWF File
                                                              Flex harUI Adobe Employee

                                                              Depending on the player version, there could be an issue with registered

                                                              data classes.  It could also be that the remote call infrastructure is not

                                                              "closed".

                                                              • 28. Re: Unload SWF File
                                                                r.rubio Level 1

                                                                I'm using debug player version 10.1.

                                                                 

                                                                This occurs in my vanilla configuration where i have a vanilla application that simply makes a remote call.

                                                                 

                                                                So is this an issue with the player?  Is there any work around.

                                                                 

                                                                Here is an image of the profile trace.  Is the culprit the SWFGroupBridge?

                                                                 

                                                                vanillaProfile.jpg

                                                                • 29. Re: Unload SWF File
                                                                  Flex harUI Adobe Employee

                                                                  I doubt it is the SWFBridgeGroup.  I would expect it is there regardless of

                                                                  whether you make the remote call or not.

                                                                   

                                                                  Are you using RemoteObject or NetConnection directly or something else?  One

                                                                  thing you can do is compare the memory snapshot before and after the remote

                                                                  call.  One of those objects is likely responsible for the leak.

                                                                  • 30. Re: Unload SWF File
                                                                    r.rubio Level 1

                                                                    I'm using Remote object going over amf channel.

                                                                     

                                                                    Could not see any difference.  I've attached the profiler trace.  The top system manager does not make a remote call and the bottom one does.

                                                                     

                                                                    Eventually the top one gets unloaded but the bottom one never does.

                                                                     

                                                                    The steps i followed are as follows

                                                                     

                                                                    1. portal application runs and has two buttons (load and unload).
                                                                    2. Click load.  this loads vanilla application into sandbox
                                                                    3. vanilla application has one (button to make remote call through amf channel).
                                                                    4. Click Unload.
                                                                    5. Click run garbage collector on profiler
                                                                    6. Click take snap shot.
                                                                    7. Click load. this loads vanilla application into sandbox
                                                                    8. Click button to make procedure call on vanilla application
                                                                    9. Click unload.
                                                                    10. Click run garbage collector on profiler
                                                                    11. Click take snap shot.
                                                                    12. Repeat (eventually every application that was loaded without making a remote call is unloaded and every application that does make a procedure call remains in memory).

                                                                     

                                                                    Here is the profiler trace.  The top system manager is where no remote call is made.  The bottom one shows the trace when a remote call was made:

                                                                    VanillaTrace.jpg

                                                                    • 31. Re: Unload SWF File
                                                                      Flex harUI Adobe Employee

                                                                      I doubt the SystemManager is the issue.  I'd look at the quantity and names

                                                                      of every class in the snapshots to see what the difference is.  I think

                                                                      someone recently wrote about having to disconnect the RO in order to allow

                                                                      unloading.

                                                                      • 32. Re: Unload SWF File
                                                                        r.rubio Level 1

                                                                        Ok.  Vanilla configuration unloads now.

                                                                         

                                                                        RemoteObject.disconnect needs to be called.

                                                                         

                                                                        Thanks Alex.

                                                                        • 33. Re: Unload SWF File
                                                                          cosmacol Level 1

                                                                          I just discovered a related issue, that could also be the cause of the unload problem.

                                                                           

                                                                          Some of the classes in the loaded subapplication have a [RemoteAlias] metadata, because they are viewobjects that map to remote java classes. I noticed that, unloading and reloading the same subapps breaks the deserialization behaviour, because the registered class for the alias is still pointing to the class in "old" application domain.

                                                                           

                                                                          Probably the class definition is held by the class alias registry, that in FP 10.1 (and AIR 2.0, I think) is mantained per SecurityDomain. I have to load the subapps in the top-level SecurityDomain, via Loader.loadBytes, due to NativeApplication security restrictions (child security domains cannot contain AIR-based subapps, they complain that NativeApplication can't be accessed from other security domains).

                                                                           

                                                                          I verified this behavior using this simple code in the subapps:

                                                                           

                                                                          // registerClassAlias("my.package.MyClass", MyClass);

                                                                          var myClassByAlias:Class = getClassByAlias("my.package.MyClass");

                                                                          var myClass:Class = MyClass;

                                                                          trace("class definition match? " + (myClassByAlias === myClass ? "YES" : "NO"));

                                                                           

                                                                          The first time my subapps loads, the match is YES, the second time is NO. If I uncomment the first line, overwriting any old registered class for the alias, it always works correctly.

                                                                           

                                                                          I think that this registry is holding some class references, and thus preventing the whole ApplicationDomain upload. It also produce other blocking errors, such as type coercion errors when subapps try to cast objects to their expected class.

                                                                           

                                                                          Is there any way to debug the class alias registry? Or, AIR sub-apps be loaded in their own SecurityDomain?

                                                                           

                                                                          Thank you

                                                                          Cosma Colanicchia

                                                                          • 34. Re: Unload SWF File
                                                                            Darrell Loverin Level 4

                                                                            Can you define the classes with the in the top-level application? This would cause the registerClassAlias() calls to be executed in the main application and avoid the problem.

                                                                             

                                                                             

                                                                            -Darrell

                                                                            • 35. Re: Unload SWF File
                                                                              cosmacol Level 1

                                                                              Hi Darrel,

                                                                               

                                                                              thanks, but I can't move the alias registration in the main application, cause the top-level app is not aware of the content that will be loaded as sub apps.

                                                                               

                                                                              I'm experimenting another way, avoiding the [RemoteAlias] and explicitly calling registerClassAlias, using the fully qualified name of the class along with a subapp-specific prefix.. this should avoid the type coercion errors when multiple application share the same libraries (however, the custom registerClassAlias will be required also server-side, on the ClassAliasRegistry).

                                                                               

                                                                              Once I setup a class to manually manage alias registration, I will try to unregister those classes from the registry on sub apps shutdown.. registerClassAlias won't accept a *null* value for the Class argument, and there is no unregisterClassAlias method in Flash, so I'll try to remap the alias to the Object class. I hope that this will break the dependency from the global class alias registry towards the subapp-specific class.