7 Replies Latest reply on Apr 14, 2010 9:53 PM by Flex harUI

    SWFLoader Unload Problem

    chinyuan84

      Hi,

       

      After doing some searching on the web I still couldn't slove the memory usage problem.

      I have tried using unloadAndStop function and also tried using setting source to empty, but none of these worked for me.

      Even I used the hack way to force GC to work, the memory still occupied by the old swf.

      The situation is each time a new swf file loaded, the memory usage is more and more larger.

      The unload action seems never worked.

      I hope any one could help me about this problem.

      The following is my source code.

      Thanks.

       

      PS:1. My flash player version: 10

            2. I use Flex builder to build the file.

       

       

      Source Code:

       

         <mx:Script>
              <![CDATA[
                  [Bindable]
                  public var selectedItem:Object;    
                  private function unloadSWF(evt:MouseEvent):void{
                      displayItem.source = "";
                  }          
                  private function nullSWF(evt:MouseEvent):void{
                      displayItem.unloadAndStop();
                  }           
                  private function setSWF(evt:Event):void{               
                      selectedItem=(evt.target).selectedItem;
                      displayItem.load(selectedItem.module);               
                  }           
              ]]>
          </mx:Script>
          <mx:ComboBox
              width="215"
              labelField="label"
              close="setSWF(event)">
              <mx:dataProvider>
                  <mx:Object label="Select Coverage"/>       
                  <mx:Object
                      label="Life Insurance"
                      module="JSCaller.swf"
                  />
                  <mx:Object
                      label="Auto Insurance"
                      module="JScaller2.swf"
                  />         
              </mx:dataProvider>
          </mx:ComboBox>

       

          <mx:Panel width="100%" height="100%">
              <mx:SWFLoader id="displayItem" width="100%" height="100%"/>
          </mx:Panel>
          <mx:HBox>
              <mx:Button label="Unload" click="unloadSWF(event)"/>
              <mx:Button label="Nullify" click="nullSWF(event)"/>
          </mx:HBox>

        • 1. Re: SWFLoader Unload Problem
          Darrell Loverin Level 4

          1. What version of Flex are you using?

          2. Have you checked for leaks caused by styles or resource bundles?

          3. Please paste the smallest possible code for JSCaller.swf that does not unload.

           

           

          -Darrell

          • 2. Re: SWFLoader Unload Problem
            chinyuan84 Level 1

            Hi,

             

            Thanks for reply.

             

            1. What version of Flex are you using?

            The Flex builder I used is Flex Builder 3 and the SDK version is 3.4.

             

            2. Have you checked for leaks caused by styles or resource bundles?

            I though I didn't use any other resources.

             

            3. Please paste the smallest possible code for JSCaller.swf that does not unload.

            The following is the source code of JSCaller.swf and  the code of JSCaller2.swf as the same as JSCaller1.swf.

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="0x000000" borderStyle="none" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#A9F87E, #74C61C]">
                <mx:Label id="lb1" text="fs3"/>
                <mx:Label id="lb2" y="23" text="fs4"/>
            </mx:Application>

            • 3. Re: SWFLoader Unload Problem
              Darrell Loverin Level 4

              Using the profile I can see the sub-application garbage collected after it is unloaded. There is no leak in your application. But there is a known problem with memory growing (System.totalMemory) when using the debug player with debug applications. To accurately check memory, use the release version of the player with release builds.

               

               

              -Darrell

              • 4. Re: SWFLoader Unload Problem
                FTQuest Level 3


                Darrell Loverin wrote:

                 

                To accurately check memory, use the release version of the player with release builds.

                 

                 

                -Darrell

                Could you either point out the resources to read, or elaborate a little bit on how to profile the release builds?

                 

                Thanks,

                FTQuest

                • 5. Re: SWFLoader Unload Problem
                  Darrell Loverin Level 4

                  Release builds can't be profiled. Release builds need to be used when you are NOT using the profiler and are using System.totalMemory to track memory usage.

                   

                   

                  -Darrell

                  • 6. Re: SWFLoader Unload Problem
                    chinyuan84 Level 1

                    Thanks for your checking.

                    Since those codes are no problem.Is there any possible the problem may cause by me using flash 10.1.x or AIR 2.0 beta2.

                    If needed I could send my zipped project code. Because the profiler shows that Cumulative Memory keep increasing,

                    Windows management also shows me the same result.

                    • 7. Re: SWFLoader Unload Problem
                      Flex harUI Adobe Employee

                      Cumulative memory does not matter.  Peak Memory matters and should not grow.

                      To identify leaks, it is best to avoid Loitering Objects view and simply

                      compare Memory Snapshots by hand, looking at the instance counts.   Don't

                      forget to remove all filters before doing so.

                       

                      There are several posts on my blog about finding memory leaks and what to

                      look for.

                       

                      --

                      Alex Harui

                      Flex SDK Team

                      Adobe System, Inc.

                      http://blogs.adobe.com/aharui