11 Replies Latest reply on May 3, 2012 11:05 PM by evyavan

    SWFLoader.unloadAndStop() - does it unload swf and release memory?

    ilya_k Level 1

      Hi all,

       

      Do SWFLoader FP10 unloadAndStop() and GC really unload swf?

      I have simpliest test case possible when parent app creates new SWFLoader, loads sub app and then unloads it.

      Every time when it does it I see memory grows. The sub app is tiny:

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

          <mx:Label id="idLabel" color="blue" text="This is embedded application."/>   

      </mx:Application>

       

      The parent application is also simple

       

      public function loadSwf(name:String):void

      {

        loader.addEventListener(Event.COMPLETE, completeHandle, false, 0, true);   

                     

        loader.showBusyCursor = true;

        loader.scaleContent = true;

        loader.source=name;     // name is subappswf.swf the

        loader.load();

      }

       

      private function completeHandle(event:Event):void

      {

        loader.removeEventListener(Event.COMPLETE, completeHandle);

        loader.unloadAndStop(true);

      }

       

      Profiler shows decent Peak Memory and even Cumulative Memory does not seem horrible. There are no objects hanging in sub-application except SystemManager. But Google Chrom Task Manager shows the real picture:  Shockwave Flash memory grows and as soon it reaches threshold ~0.5 GB, application becomes unresponsive and eventually FP crashes.

       

      What else should be done to free up memory?

       

      Regards,

      Ilya

        • 1. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
          Flex harUI Adobe Employee

          Per the doc, unloadAndStop() frees up a few references and stops the

          timeline, but doesn't free up everything.  Most Actionscript references need

          to be cleaned up some other way.

           

          On every load, does peak memory in the profiler keep growing?  If so, there

          is an Actionscript reference.  Otherwise, there is some other reason that

          memory isn't being freed up.  Test on another browser and see what happens.

          1 person found this helpful
          • 2. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
            ilya_k Level 1

            Peak Memory stays steady.

            Other browsers, FF or IE for example, just crash after roughly same number of loads. Although have not tested in Opera or Safari but do not expect different behavior.

             

            Thanks Alex for quick response. This is serious issue for enterprise system management application....

             

            Regards,

            Ilya

            • 3. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
              Flex harUI Adobe Employee

              There are some issues with debug SWFs and the debugger player.  One test to

              run is to export release builds of all SWFs and use a non-debugger player

              (the official players from our website), and see if memory goes up and the

              browser craps out.

               

              Another test to run is to change the sub-swf to something really simple like

              a red square and see if memory goes up.

               

              But before you do all of that, if you are removing the SWFLoader from the

              displaylist as well, make sure you call validateNow() on the SWFLoader after

              unloadAndStop() but before removing it.

              1 person found this helpful
              • 4. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
                ilya_k Level 1

                I have tried with non-debugger FP. Same result - IE crashed.

                 

                Sub-app I am using is very simple. It creates one label (see original post). Do you

                want me to play with another one you suggested?

                 

                I have added validateNow() call. So far there is no difference but I run debugger FP.

                Will try run it in non-debugger FP.

                 

                            private function completeHandle(event:Event):void

                            {

                                trace("Load complete");

                                loader.removeEventListener(Event.COMPLETE, completeHandle);

                                loader.unloadAndStop(true);

                            }

                 

                            private function unloadHandle(event:Event):void

                            {

                                trace("Unloaded complete");

                                loader.removeEventListener(Event.UNLOAD, unloadHandle);

                                loader.validateNow();

                                idDummyCanvas.removeChild(loader);

                            }

                 

                Regards,

                Ilya

                • 5. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
                  Flex harUI Adobe Employee

                  You might have to set source=null as well, but if this was the problem I

                  would expect the profiler numbers to be increasing.  You can debug into

                  SWFLoader to see if it really calls unloadAndStop.  I would definitely try a

                  smaller non-Flex sub-app.

                   

                              private function completeHandle(event:Event):void

                              {

                                  trace("Load complete");

                                  loader.removeEventListener(Event.COMPLETE, completeHandle);

                                  loader.unloadAndStop(true);

                                    loader.source = null;

                                    loader.validateNow();

                              }

                   

                              private function unloadHandle(event:Event):void

                              {

                                  trace("Unloaded complete");

                                  loader.removeEventListener(Event.UNLOAD, unloadHandle);

                                  idDummyCanvas.removeChild(loader);

                              }

                   

                  • 6. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
                    ilya_k Level 1

                    This is iInteresting...

                     

                     

                     

                    /**

                    * Unloads an image or SWF file. After this method returns the

                    * <code>source</code> property will be null. This is only supported

                    * if the host Flash Player is version 10 or greater. If the host Flash

                    * Player is less than version 10, then this method will unload the

                    * content the same way as if <code>source</code> was set to null.

                    *

                    * This method attempts to unload SWF files by removing references to

                    * EventDispatcher, NetConnection, Timer, Sound, or Video objects of the

                    * child SWF file. As a result, the following occurs for the child SWF file

                    * and the child SWF file's display list:

                    * <ul>

                    * <li>Sounds are stopped.</li>

                    * <li>Stage event listeners are removed.</li>

                    * <li>Event listeners for <code>enterFrame</code>,

                    * <code>frameConstructed</code>, <code>exitFrame</code>,

                    * <code>activate</code> and <code>deactivate</code> are removed.</li>

                    * <li>Timers are stopped.</li>

                    * <li>Camera and Microphone instances are detached</li>

                    * <li>Movie clips are stopped.</li>

                    * </ul>

                    *

                    * @param invokeGarbageCollector Provides a hint to the garbage collector to run

                    * on the child SWF objects (<code>true</code>) or not (<code>false</code>).

                    * If you are unloading many objects asynchronously, setting the

                    * <code>gc</code> parameter to <code>false</code> might improve application

                    * performance. However, if the parameter is set to <code>false</code>, media

                    * and display objects of the child SWF file might persist in memory after

                    * the child SWF has been unloaded.

                    */

                     

                     

                    public function unloadAndStop(invokeGarbageCollector:Boolean = true):void

                    {

                    useUnloadAndStop =

                     

                    true;

                    unloadAndStopGC = invokeGarbageCollector;

                    source =

                    null; // this will cause an unload unless autoload is true

                     

                     

                    if (!autoLoad)

                    load(

                    null);

                    }

                     

                    It means that if autoload is true (default) unload will not happen and sub-app

                    will persist in memory.

                     

                    Regards,

                    Ilya

                    • 7. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
                      ilya_k Level 1

                      Setting loader.autoload = false and load manually maybe is the solution to the problem.

                      What do you think?

                       

                      Regards,

                      Ilya

                      • 8. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
                        Flex harUI Adobe Employee

                        If autoLoad is true, and you set source=null and call validateNow() right

                        after, it should cause unloadAndStop to actually be called.

                        • 9. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
                          raffialexanian

                          Hello;

                           

                          Am having the same issue, and have tried all the suggested steps here to no avail. did you ever solve this issue please?

                          Thanks

                          Raffi

                          • 10. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
                            ilya_k Level 1

                            I think I did. Just follow the steps Alex described.

                             

                            Good luck,

                            Ilya

                            • 11. Re: SWFLoader.unloadAndStop() - does it unload swf and release memory?
                              evyavan

                              Hi there, I have a problem with the method you explained though it works fine for me with the installed app.

                              When I try to debug the code Adobe AIR debug launcher crashes, but I could compile the code and export a release build. The release build is working fine.

                               

                              I have a canvas which loads a swfLoader and no clicking a button or another component on the screen the content loaded into this swfLoader is released by this folowing command and the whole canvas is removed from its parent container.

                               

                              swfloader.unloadAndStop();

                              swfloader.source = null;

                              swfloader.validateNow();

                               

                              Then in the control command file I declare and define an object of another mxml file which contains another swfLoader and the debug launcher crashes at this point. I noticed that the command runs fine if a former swfLoader.unloadAndStop() is not called. It would be great if you could explain to me on how to avoid this crash. The debug launcher is crashing everytime it encounters such  a scenario though the installed app works fine.

                               

                              --Update--

                               

                              I removed the '*.unloadAndStop()' line and it works fine. But how do I know if the swf is really unloaded from the memory?