4 Replies Latest reply on May 18, 2006 12:37 AM by slawu

    How to force a GC cycle?

    slawu
      Hi,
      I'm writting some pretty complex app in Flash. I do a lot of loadMovie, unloadMovie and after a while my app occupies about 40MB in memory and it stays on this level even when I unload all loaded movie clips.

      How can I force garbage collection? Is there a way to tell Flash to free some ammount of unused memory?
        • 1. Re: How to force a GC cycle?
          samdl1
          Slawu,

          I'm not 100% on this but as I understand it, the unloadMovie function takes the movieclip off the stage and keeps it in the buffer memory. There are two ways around it which may or may not be applicable to your app - the first is to replace the movieclip which another at the same depth, destroying the instance. The other way is the removeMovieClip method which I think takes away the instance completely.

          Any second opinions?
          I hope this helps

          Sam
          • 2. Re: How to force a GC cycle?
            slawu Level 1
            Well, to be honest, this wasn't very helpful.

            I created two movies film1.swf and film2.swf. In film1.swf I put two buttons "Load" and "Unload" and the code:

            var image:MovieClip;

            this.loadBtn.onRelease = function() {
            image = this.createEmptyMovieClip("image", this.getNextHighestDepth());
            image.loadMovie("film2.swf");
            image._x = 0;
            image._y = 22;
            };

            this.unloadBtn.onRelease = function() {
            image.unloadMovie();
            image.removeMovieClip();
            };

            film2.swf doesn't do anything, only allocates memory:

            var arr = new Array("1","2","a","b","-","+","A","B");

            function dbl() {
            arr = arr.concat(arr);
            }

            setInterval(dbl, 500);

            I publish film1.swf, film1.html and film2.swf. Then I lunch Firefox and open film1.html. TaskManager says that Firefox uses about 30MB of memory. I press "Load" and wait a couple of seconds. When TaskManager indicates that Firefox uses about 70MB I press "Unload". Nothing happens. Memory usage stays at the level of 70MB. I wait a couple of minutes and still nothing happens. Memory is freed when I close the Firefox tab in which I opened film1.html.

            How can I force the memory to be freed earlier? I'm writting some pretty complex application which loads and unloads many movies and it has to be opened for a long time (I mean the user may want to leave it open and work on something else. This app is a "background application"). I would like to decide to free unused memory when my app isn't doing anything usefull.
            • 3. Re: How to force a GC cycle?
              Level 7
              not sure at all, but did you try:

              temp = this.getNextHighestDepth();

              this.loadBtn.onRelease = function() {

              image = this.createEmptyMovieClip("image", temp);
              image.loadMovie("film2.swf");
              image._x = 0;
              image._y = 22;
              };

              this.unloadBtn.onRelease = function() {
              image = this.createEmptyMovieClip("image", temp)
              };






              "slawu" <webforumsuser@macromedia.com> schrieb im Newsbeitrag
              news:e49epb$een$1@forums.macromedia.com...
              > Hi,
              > I'm writting some pretty complex app in Flash. I do a lot of
              loadMovie,
              > unloadMovie and after a while my app occupies about 40MB in memory and it
              stays
              > on this level even when I unload all loaded movie clips.
              >
              > How can I force garbage collection? Is there a way to tell Flash to free
              some
              > ammount of unused memory?
              >


              • 4. Re: How to force a GC cycle?
                slawu Level 1
                No it doesn't help.

                I even put "delete arr" in the onUload() event handler and nothing.

                Any other ideas?