4 Replies Latest reply on Nov 2, 2013 12:54 PM by Andi-MUC

    unload of movie does not free memory

    Andi-MUC

      Hi,

       

      I built up a small tool in AIR 2.5 for technical documentation. Therefore to explain each step in the documentation, beneath some text and other objects always a video is to be displayed.

       

      My problem is now, that I need to display one video after the other.The single videos are small (MP4 about 2-4 MB) , but after showing about 50-100 assembly steps/videos I end up with about 1.9 GB of used memory (only the AIR-app) and a following crash.

       

      I tried different approaches to get rid of the video data (around 2 days of try and error and google), but could not manage it.

       

      Any help is appreciated because it's very urgent. As usual ;-)

       

      Here is the interesting part of the code:

       

       

      private var loadedArray:Array = new Array();
                  

      private var VideoPl:VideoPlayer;


      private function loadVideo(event:MouseEvent):void
      {
          if(loadedArray.length >0)
          {
              VideoPl.stop();
              VideoPl.source = null;
              loadedArray[0].removeElement(VideoPl);
              VideoPl = null;
              loadedArray.pop();
              startGCCycle();
          }
             

       

          VideoPl = new VideoPlayer();

       

          VideoPl.width = 320;
          VideoPl.height = 265;
          VideoPl.left = 10;
          VideoPl.top = 10;
          VideoPl.setStyle("chromeColor", "#CCCCCC");
          VideoPl.autoPlay = false;
          VideoPl.autoRewind = false;
          VideoPl.visible = true;
          VideoPl.cachePolicy = "off";
          VideoPl.source = event.target.name; //Path to local file
          VideoPl.name = "mmVideoPlayer";
          event.target.parent.addElement(VideoPl) // add it to a VGroup (= event.target.parent)
          loadedArray.push(event.target.parent);
      }

       

       

      private var gcCount:int;


      private function startGCCycle():void

      {
           gcCount = 0;
           addEventListener(Event.ENTER_FRAME, doGC);
      }
      private function doGC(evt:Event):void

      {
           flash.system.System.gc();
           if(++gcCount > 1){
                removeEventListener(Event.ENTER_FRAME, doGC);
                setTimeout(lastGC, 40);
           }
      }

      Thanks in advance for your help...

       

      Reg.

      Andi

        • 1. Re: unload of movie does not free memory
          UbuntuPenguin Level 4

          Don't really know much about flash video.  But in terms of garbage collection, are you sure there are

          no references to said videos anywhere in the application.  Once the garbage collector sees that there are no references to an object,

          it should cleanup the resource...eventually.  Speaking of references, when you add your eventlisteners are you using weak references.  If not, the listener by having a reference to video will prevent the video from being garbage collected.  For instance.

           

          VideoWrapper vw = new VideoWrapper();

          vw.video = myVideoResource;

          vw.addEventListener( VideoWrapperEvent.VWEvent , doSomething );


          ...

          later on in code

          ...

          vw = null.

           

          Now here we would expect the myVideoResource to be gc'ed since the object containing it ( vw the videowraper) has no other references.  But the listener indeed holds a reference to the wrapper, so it, and its video resource are here to stay.  When we add the listener, we need to set the "useWeakReference" to true like so.

           

          vw.addEventListener( VideoWrapperEvent.VWEvent , doSomething , false , 0 , true );

           

          Of course , I am shooting from the hip on this one.

          1 person found this helpful
          • 2. Re: unload of movie does not free memory
            Andi-MUC Level 1

            Hi Ubuntu Penguin,

             

            THX for your fast reply, but the code you see there is definitely the only code (at the moment) regarding the video object.

             

            I already read about the problem with the remaining eventListeners, but I did not add any. Based on your post I thought: Hey, as the VideoPlayer-object owns a Play/Pause... -Button by default, and maybe there are some Mouse-Click-EventListeners still remaining after  "destroying" the object. So I tried the same thing with the spark VideoDisplay, which onws no Buttons at all. => Same problem.

             

            So if anyone knows about some eventListeners, which are started automatically by adding a spark VideoPlayer/VideoDisplay to the stage and adding Video content to it, please let me know.

             

            Kind regards,

            Andi

            • 3. Re: unload of movie does not free memory
              injpix Level 3
              VideoWrapper vw = new VideoWrapper();

              You must program in another language.  Good post by the way.

              • 4. Re: unload of movie does not free memory
                Andi-MUC Level 1

                Ok, for all having the same problem I found the issue long tiime ago, but saw my own post here on adding a new question to the board.

                 

                The VideoPlayer class (at least in the state I used it at these times) wasn't developed very well (by Adobe I think), as ther ehad been a lot or EventHandlers beeing opened, but never closed, whereas other ones had been closed, whcih never had been added...

                 

                So if you suffer the same or kind of similar problems, take a look through the code of the class, and check especially for the event handlers.

                 

                Best regards,
                Andi