11 Replies Latest reply on Nov 18, 2010 9:43 PM by Flex harUI

    Why the borwser used memory never release


      Hi, i got an awful problem . My application is split into multi modules and a Tabbara as navigator.
      When modules are loaded and unloaded dynamically  the browser(chrome with flash player release version 10)  used memory increases continually .
      It looks like a memry leak problem.
      So i used profiler to check it,but the profiler shows that after a module had been unload the moudle and relevant components activity instance go dowm to 0.
      And at the same time the System.totalMemory decrease also.
      But the question is the browser used memory never decrease,even if i export release build and use a release version FlashPlay to visit the app.

      I am stuck,why the profiler show the module have benn unloaded completely,and the System.totalMemory  decrease but the browser used memory never decrease.

      I am wondering why the browse used memory never release when the profile show that a module was unloaded(all the relevant components activity instance go dowm to 0 ).

      Someone has any idea how i can solve this problem ?

        • 1. Re: Why the borwser used memory never release
          Flex harUI Adobe Employee

          Using a debug version, make sure you see in the console.

          Otherwise, the instances are all gone, but the classes in the

          applicationdomain are not.


          Otherwise, I have seen an situation where browser memory grows and then goes

          back down when you minimize the browser.  We don't have a small reproducible

          test case for it so it remains unresolved.

          • 2. Re: Why the borwser used memory never release
            测试信息 Level 1

                        Alex,thanks for your reply very much.
                        I followed your guide,and found out that the UnloadSWF  message show in the consolem sometimes,not every time,but the eventListener for ModuleEvent.UNLOAD execute every time.
                        And i did not know why.I have checked my code so many times,and can not figure out what is the cause.
                        So i post my code here,hope some one can help me.Thanks.

            //method to load module
            private function loadModule(moduleUrl:String):void {                    
                                var moduleInfo:IModuleInfo  = ModuleManager.getModule(moduleUrl);
                                //moduleInfoRef is an object,to hold  a reference to  moduleInfo
                                moduleInfo.addEventListener(mx.events.ModuleEvent.READY, onModuleReady ) ;
                 //module ready  handler
                           private     function onModuleReady(event:mx.events.ModuleEvent):void {
                                var flexModuleFactory:IFlexModuleFactory  =event.module.factory;                     
                                var module:mx.modules.Module = flexModuleFactory.create() as mx.modules.Module;
                                     //create a new NavigaorContent to hold the module instance
                                     var container:NavigatorContent = new NavigatorContent();
                                     //set the module url to the NavigatorContent id
                                     container.percentWidth = 100;
                                     container.percentHeight = 100;
                                     //vsModules is a ViewStack
                           //module unload handler,this mehtod execute every time when the removeModule called.
                           private     function onModuleUnload(event:mx.events.ModuleEvent):void {
                                trace(event.module.url+" has been unloded!");
                 //unload the module
                           private function removeModule(nav:NavigatorContent):void{
                                if(nav==null) return;
                                var moduleInfo:IModuleInfo  = moduleInfoRef[nav.id] as IModuleInfo;
                                moduleInfo.removeEventListener(mx.events.ModuleEvent.READY, onModuleReady ) ;
                                moduleInfo.removeEventListener(mx.events.ModuleEvent.ERROR, onModuleError ) ;
                                moduleInfo.removeEventListener(mx.events.ModuleEvent.UNLOAD, onModuleUnload ) ;
                                //set to null 
                                //force gc here
                                     new LocalConnection().connect( "somethingDoesNotExist" );
                                     new LocalConnection().connect( "somethingDoesNotExist" );
                                catch (e:Error) {} 
            • 3. Re: Why the borwser used memory never release
              Flex harUI Adobe Employee

              Add a button that calls the LocalConnection code and hit it several times

              and see if you get the .  Sometimes it doesn't happen right away.

              If it never happens, then start checking the profiler again.

              • 4. Re: Why the borwser used memory never release
                测试信息 Level 1

                Alex:Thanks again.

                After many tries,i found out if i change the code moduleInfo.load(ApplicationDomain.currentDomain)tomoduleInfo.load()the console indeed trace the info :[Unload SWF]xxxx.swf ervery time.To confirm that,i open profiler,and after load and unload a moudletimes,the activity instance go down to 0.Unfortunately when i export release build and use Chrome( wiht Flash Player release version 10 plug-in,before visit the application i cleaned up the borowser cache) visit the application,after load &unlaod the same module times,the browser used memory increase always.

                It's really make me upset,the console show the unload message,and the profileractivity instance is zero,but why the browser used memory always increase,event if click a button to call the codenew LocalConnection().connect( "somethingDoesNotExist" ); one hundred times!

                So what cause the browser used memory increase always?

                Hope you can help!

                • 5. Re: Why the borwser used memory never release
                  测试信息 Level 1

                  Alex,i recheck the profiler,and found that after the  moudle(an empty module without any children) load&unload(when debugging console show the message,and the profiler show module activity instance is0,) a ModuleInfo class stay in the memory.is the ModuleInfo class cause the browser used memory increase?

                  BTW,actually the browser used memory is not always increase,it will be stay in a certain number after many times load&unlaod,but the browser used memory  increased about 10M than the the initalize used memory.

                  In my real project there are about 30 moudle,if each  module load&reload many times,the browser used memory will go to a huge number,and the  browser  respond slowly .

                  • 6. Re: Why the borwser used memory never release
                    Flex harUI Adobe Employee

                    Which version of Flex?  I thought we fixed that issue.  Also, that might

                    create a small leak, but shouldn't create a big one.

                    • 8. Re: Why the borwser used memory never release
                      Flex harUI Adobe Employee

                      The moduleInfo implementation changed in 4.1

                      • 9. Re: Why the borwser used memory never release
                        测试信息 Level 1

                        Thanks a lot,i will try SDK4.1

                        • 10. Re: Why the borwser used memory never release
                          Gh(ºº)sT Level 1



                          I'm using Flash Builder 4 with SDK and I my application keeps crashing the memory browser.


                          Output console appears:



                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\136
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\137
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\138
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\139
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\140
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\141
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\142
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\143
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\144
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\145
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\146
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\147
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\148
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\149
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\150
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\151
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\152
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\153
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\154
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\155
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\156
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\157
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\158
                          [Unload SWF] C:\Appl\bin-debug\MyApp.swf\[[DYNAMIC]]\172



                          as for the same lines but with the load tag.


                          Is this a sign of bad memory usage!? Can I prevent Flash Builder from loading/unloading SWF constantly or prevent it from showing alll the messages?


                          Thanks in advance,


                          Bruno Pimenta

                          • 11. Re: Why the borwser used memory never release
                            Flex harUI Adobe Employee

                            is usually a good thing.  Memory is being released.  But maybe

                            you are constantly loading and unloading an embedded SWF or bytearray and

                            that can cause memory fragmentation.  Try to find out why so many SWFs are

                            being loaded and try to find a design that caches or recycles them.