4 Replies Latest reply on Dec 16, 2010 10:59 PM by Flex harUI

    The Flex Modules Nightmare. RE-Loading? Help!?

    Gnomann

      Hello all from a weary developer,

       

      I've found material about the unloading of Flex modules (and the nightmare it can be). In particular I'm talking about modules that inherit from ModuleBase (not Module) and are loaded via the ModuleManager and an IModuleInfo instance. They load ok. Unloading (via the IModuleInfo .unload method) works (at least on the surface). I know that the releasing of all references to the module-instance (created via the factory) and perhaps the iModuleInfo instance has to be done to completely unload the module. Have yet to do this. But my problem may not be that exactly...

       

      I'm trying to reload a module on the fly to access a modified version of a class. To do this, i'm trying to (re-)load the class-containing module into a different application-domain than the first time i loaded it. However, the second time i load it (the reload), the new application-domain housing the new module-data does not register the nested class as being defined. Thus, i have a main app i keep running in dev, and then i go back code from a module, and then rebuild/compile it, then try to reload the module to access the NEW code, while the main dev-app continues to run. It simply does not seem to load the class-defs into the new (2nd) app-domain.

       

      load#1: module into child app-domain of currentDomain.

      load#2: module into new child app-domain of currentDomain.

       

      It would seem that this "should" be able to be done, even if the classDefs from module#1 (loaded into app-domain#1) remain intact, as it would populate the separate space of app-domain#2 with the classes from the module. They just don't seem to exist in the second domain.

       

      Any help would be more that appreciated. Have already spent many days on this, but it may be many days more to try to exhaust all the possibilities on this, and i'm already maximally frusted.

       

      Direct questions:

       

      1) Any INCREDIBLY DETAILED explanation of all this, possibly even source-code? All online docs are unsatisfactory.

      2) Will working with modules (subclasses of Module) rather than moduleBases be any easier? Can they be RE-Loaded on the fly?

      3) Will completely unloading and gc-ing the first module-stuff do the trick? Will new classDefs be RE-loaded into a new app-domain?

      4) Do i have to completely gc the first AppDomain to wipe out those class-defs, even tho i logically "shouldn't" have to?

       

      Any other help greatly appreciated.

       

      I'll name my firstborn after anyone who can help me solve this -- even if the gender doesn't match!

       

      much thanks in advance,

       

      -- niall

        • 1. Re: The Flex Modules Nightmare. RE-Loading? Help!?
          Flex harUI Adobe Employee

          Which version of Flex are you using?  I'm not sure this is even possible on

          the official versions.  We may have finally cleaned up an issue that would

          prevent doing what you want.

           

          For any url, the IModuleInfo is cached in a dictionary.  Until you get rid

          of the IModuleInfo, any subsequent attempt to load the same url won't

          actually fetch an updated SWF, it will use the existing IModuleInfo.factory.

          I believe there was a problem dereferencing IModuleInfo's in the past.

          Check the profiler to make sure they have gone away, otherwise you have no

          chance of this working.

           

          Another option you have is to generate unique URLs for each revision of the

          module, even by adding a fake url param to it.  You might need to do that

          anyway to avoid picking up a stale SWF from the browser cache.

          1 person found this helpful
          • 2. Re: The Flex Modules Nightmare. RE-Loading? Help!?
            Gnomann Level 1

            Thank you very much, 'Flex harUI' for the help. That is insightful. And i guess i shouldn't be surprised since you are (or at least seem to be by the tag) an Adobe employee. I may have more questions about this. I'm going to go do some tests to see if i can get the engine to devour the initial ModuleInfo (probably a ModuleInfoProxy) so that it will actually reload the module into the new ApplicationDomain.

             

            If you have any more instructions on how to ensure that i actually get the IModInfo to be g-collected that would help. As far as i know, i just have to remove all references to it, and call System.gc(). I've run across things like the following snippet to try to get the gc to actually run a sweep. If this (or something else) is needed. please let me know.

             

            try {
            new LocalConnection().connect('foo');
            new LocalConnection().connect('foo');
            } catch (e:*) {}
            // the GC will perform a full mark/sweep on the second call.

             

            If i can actually ge this working it's going to save me an ENORMOUS amount of time.


            Thanks again.

             

             

            -- niall

            • 3. Re: The Flex Modules Nightmare. RE-Loading? Help!?
              Gnomann Level 1

              PS -- I'm using the trial version of Flash Builder 4. Depending on how some of this turns out will determine if actually plunge back into Flex, where i was for a few years until taking a hiatus.

               

              thx.

              • 4. Re: The Flex Modules Nightmare. RE-Loading? Help!?
                Flex harUI Adobe Employee

                I think 4.1 has a fix.  I would use the local connection "hack".

                System.gc() does not work on the production player.