1 Reply Latest reply on Feb 6, 2009 3:41 PM by Joe ... Ward

    Window Memory usage even after closing windows

    jbenson@oper8 Level 2
      I've included links to a test app that does nothing but launch a window, play a sound, close window / repeat.

      When application launches it uses about 20mb of memory. When you click on the only button, it will launch a secondary window that will simply play a wav file. (I set the volume low but you may want to mute it :D)

      After launching and closing the window several times the memory usage goes up considerably and *never* falls back a significant %. (I got it to about 100MB before I decided to quit trying to increase the memory usage. Right now it's been running w/o any user interaction since opening about 10 windows and it's fairly stable at around 61MB (although that appears to be increasing w/o user interaction).

      Does anyone know of any methods I can use to ensure that the memory consumed by secondary windows does not just persist forever even after closing the window? Is there something I'm doing wrong here?

      Example Code:
      http://www.vf-server.com/air/memorytest.air (AIR)
      http://www.vf-server.com/air/memorytest.zip (source ZIP)

      Note: When I *minimize* the window it looks like garbage collection is forced and app drops back to 11MB (on restore back to 19mb).


      Edit: note in your task manager, application appears as JBTest.exe
        • 1. Window Memory usage even after closing windows
          Joe ... Ward Level 4
          You can call System.gc() to force the garbage collector to run.

          Try removing the event listeners when they aren't needed anymore. I think it is more difficult for the gc to cleanup objects when there are host objects (like Sound) refering to JavaScript objects and JavaScript objects refering to host objects, so you need to be especially careful about those. It SHOULD clean them up eventually, but it may take longer for it to figure out that those objects are no longer in use.

          You might also clear the secondaryWindow reference in the parent document when the window closes. That reference might retard garbage collection, too.