4 Replies Latest reply on Oct 15, 2009 6:04 PM by hongyu_sj

    module unload issue

    hongyu_sj

      Hi,

      We have used quite a lot of modules in our aploication. And we found that even though we tried to unload the modules, the modules instances still hanged in the memory and not GCed. We have tried several recommendations from Alex Harui's blog (on memory leak): we removed all mx:Style tags from our modules. We use weak reference for event listeners etc.

       

      One thing that I am not sure is, we use Cairngorm framework, the format when we add an event listener is as:

       

      CairngormEventDispatcher.getInstance().addEventListener(xxx, xxx, false, 0, true);

       

      According to Alex's blog, that will cause CairngormEventDispatcher.getInstance() has a reference to the module object. Is this the reason that the module is not GCed?

       

      Thanks,

       

      Hong

        • 1. Re: module unload issue
          Flex harUI Adobe Employee

          That should generate a weak reference so it shouldn't be a problem.  Have examined all other back-references to the module using the Profiler?

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: module unload issue
            hongyu_sj Level 1

            Hi Alex,

            Thanks for clarification. Now I know that it's not the event listener that cause the module memory leak.

             

            I did use profiler to find loitering objects. But there are so many loitering objects reported and also take long time to eliminate the circular references. If I am sure that a module is definitely causing memory leak, and looking at its object reference list, I found some Objects (target as property) has refer it. Will this be a problem? How can I identify this Object in my module code? I have searched my module there is no Object declared and no target reference.

             

            Thanks,

             

            Hong

             

            BTW, it will be really nice if profiler can filter out circular references for users. To profile a large application, looking through loitering objects and their references can be very time consuming, and big hassle.

            • 3. Re: module unload issue
              Flex harUI Adobe Employee

              If you check the box to show object allocation traces then you can see the code where the object was created.

               

              You might also try Flex 4 beta2.  The profiler will eliminate cycles so it can be easier to find out what is going on.  Also note that loitering objects can generate false positives.  See the profiler post on my blog for more details.

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui

              1 person found this helpful
              • 4. Re: module unload issue
                hongyu_sj Level 1

                Hi Alex,

                I tried Flash Builder 4, the profiler indeed eliminated circular references. It helps a lot to identified the problem, even though I still saw some memory leaks and have to continue work on fixing them :-)

                 

                I still have some questions about unload modules: I have some modules that need to do cleanup at the time of unload. I used ModuleLoader to load/unload Module at runtime. I understand that ModuleEvent.UNLOAD is dispatched at the time unloadModule. But I can't receive this event from module itself. I tested and only ModuleLoader can receive this event. Sone articles suggested to create Halt() / Dispoase() in module, but how can these method be called?

                 

                Thanks,

                 

                Hong