6 Replies Latest reply on Aug 17, 2007 10:09 PM by jfillman

    Garbage Collector Question

    jfillman Level 1
      I'm creating an app that requires a number of addChildren and removeAllChildren commands. I know that when a child is removed, it doesn't get removed from the application completely until the garbage collector runs. My concern, of course, is that the app will quickly slow down because there are too many children out there that are waiting to be removed. This is an app that will likely be up and running for several (6-8) hours per day, and could easily see the creating and removal of thousands of children.

      My assumption is that this work the same for AIR application as it does for straight Flex application. If anyone knows differently, please let me know.
        • 1. Re: Garbage Collector Question
          unfortunately at this point there isn't a way to programmatically instantiate the Garbage Collection. it just "does it when it feels its needed". this article sums up any questions you could possibly have with garbage collection.

          • 2. Re: Garbage Collector Question
            jfillman Level 1
            Very interesting. I hope Adobe gives us more control of this process soon! If anyone would know when something is no longer needed, it would be me the author of my application.
            • 3. Re: Garbage Collector Question
              ntsiii Level 3
              Someone has found a way to trigger garbage collection, as I recall using localConnection?
              • 4. Re: Garbage Collector Question
                jfillman Level 1
                I've tried this and either it doesn't work, or there is still some reference out there that I cannot locate. All my eventListeners are weakly referenced. Can anyone give me some ideas as to how to find out what reference(s) are keeping the GC from removing this from memory? I'm using AIR and Modules, which might be making this worse. In looking at the memory usage, and it keeps going up everytime I load the module. Unloading the module has essentially no impact to the the memory allocated to the application.
                • 5. Re: Garbage Collector Question
                  Does your module reference anything inside your shell application as it runs, or vice versa? If so, that may be the problem - even if you only have a single reference between the shell and the module, it'll cause the whole module to hang around in memory, even if its no longer actually doing anything. I've ran into this problem many times, and I haven't always been able to solve it.

                  I'm with you on wishing ActionScript 3 had some kind of memory management functionality exposed to the developer. Its nice not to have to manually remove everything from memory, but you lose almost as much time just trying to hunt down hanging references in your code.
                  • 6. Re: Garbage Collector Question
                    jfillman Level 1
                    I've pretty much given up on Modules, for now. I found an example on Alex Harui's Adobe blog using the localConnection hack. I've tweaked it somewhat so that it ramps up to a fixed memory size pretty quick and doesn't seem to ever exceed it. I'm looking forward to see what the final release of Flex Builder 3 includes for memory management tools. Alex Harui and others suggets that there will be tools released with Flex 3. Haven't seen any specific details, just that it's a significant and common issue among Flex developers.