1 Reply Latest reply on Aug 8, 2011 6:55 AM by kglad

    Loading External Images Causes Memory Leak

    comflashuseras2

      I have been working on an Actionscript 2.0 project that basically loads external images.
      Everytime i load and unload a new image, memory increases to 1 or 2 MBs
      If all the images are in cache, then it increased to 4 or 8 KBs
      In the unloading of images, I have removed loader and the container of the image.
      Any thoughts why it is behaving like that?
      Please find the sample code snippet below.


      ////////////
      btn_load.onRelease = function()
      {
      loadImage();
      }
      btn_unLoad.onRelease = function()
      {
      unLoadImage();
      }
      var mcListener:Object = new Object();
      var container1:MovieClip;
      var mcLoader:MovieClipLoader;
      var loader_reference = this;
      var n=0;
      function loadImage(){
      var image_arr = ["http://xyz.com/image1.png","http://xyz.com/image2.png","http://xyz.com/image3.png","http:/ /xyz.com/image4.png","http://xyz.com/image5.png"];
      var image_url = image_arr[n];
      if(n==image_arr.length-1) {
        n=0;
      }else{ 
        n++;
      }

      container1 = loader_reference.createEmptyMovieClip("container1", loader_reference.getNextHighestDepth());
      mcLoader = new MovieClipLoader();
      mcLoader.removeListener(mcListener);
      mcLoader.addListener(mcListener);
      mcListener.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number):Void {
      }
      mcListener.onLoadInit = function(target_mc:MovieClip):Void {
        target_mc._x = 300;
        target_mc._y = 200;
        target_mc._width = 300;
        target_mc._height = 250;
      }
      mcLoader.loadClip(image_url, container1);
      }
      function unLoadImage(){
        mcLoader.unloadClip(container1);
        mcLoader = null;
        container1 = null;
        removeMovieClip(loader_reference.container1);
      }
      ////////////

      Thanks in advance.