6 Replies Latest reply on Oct 1, 2010 5:12 AM by ven`

    Garbage collection

    SamuelJonasson

      Hi,

       

      I can't get OSMF object garbage collected.  I read somewhere that I should set the media property to null and then the media would unload.  I guess unloading the media itsn't enough.  What more do I have to do to get the OSMF objects garbage collected?

       

      This is what I am currently trying - but not working:

       

      _mediaPlayerSprite.mediaPlayer.stop();
      _mediaPlayerSprite.resource = null;
      _mediaPlayerSprite.media = null;   
      _mediaPlayerSprite.parent.removeChild(_mediaPlayerSprite);   
      _mediaPlayerSprite = null;

       

       

      Best,

      Sammi

        • 1. Re: Garbage collection
          SamuelJonasson Level 1

          Hmmm...

           

          I was hoping that there was an easy solution to this problem.  I am using a workaround now be "reusing" the player instead of removing it and reinstanciate.  But it doesn't feel good.

           

          How have you been making sure the player gets collected?

           

          Best,

          Sammi

          • 2. Re: Garbage collection
            weizhangstrobe Level 2

            Personally, I have not encountered a situation where I need to GC the player.

             

            -Wei Zhang

            Senior Computer Scientist

            Adobe Systems

            weizhang@adobe.com

            • 3. Re: Garbage collection
              Lenny1979

              Well... that's not that helpful, weizhangstrobe

               

              I do have a situation where I need to dispose the player: It is a large modular application, where a module is potentially loaded several times. And as we have a bunch of modules it is NOT a solution to keep all the stuff (several times) in the memory.

              Actually I am wondering why one has to explain this for literally every single Flash-component again anyway

               

              This being said: How do I unload a MediaPlayer, MediaElements (including Plugins), what do I do with the MediaFactory, etc etc? Are Streams/Downloads stopped?

               

              Thanks a lot,

              Lenny

              • 4. Re: Garbage collection
                bringrags Level 4

                You need:

                 

                mediaPlayer.media = null;

                mediaContainer.removeMediaElement(mediaElement);

                 

                I think that's basically it.  Note that we had an open bug related to memory leaks which might affect you (it's been fixed in trunk):

                 

                https://bugs.adobe.com/jira/browse/FM-949

                 

                If you're still seeing leaks after following the advice in the bug notes, then please add some details to the bug so we can quash this.

                • 5. Re: Garbage collection
                  Lenny1979 Level 1

                  Hi,

                   

                  thanks for the quick reply! I will try what you suggested, and I checked out the latest revision (#17552)

                   

                  I replied to the bug-report as well

                   

                  Best regards & thanks again,

                  Lenny

                  • 6. Re: Garbage collection
                    ven`

                    How do I figure out what the mediaElement is when the osmf is set up like this:

                     

                     

                    function create():void {

                     

                         _osmf = new MediaPlayerSprite();

                     

                         _osmf.mediaPlayer.autoPlay = true;

                         addChild(_osmf);

                         _osmf.resource = new URLResource(_url);

                    }

                     



                    function destroy():void {

                         _osmf.mediaPlayer.stop();

                     

                         _osmf.mediaPlayer.media = null;

                         _osmf.mediaContainer.removeMediaElement( ???? );

                     

                         _osmf.resource = null;

                         _osmf.media = null;   
                         removeChild(
                    _osmf);   
                        
                    _osmf = null;

                    }

                     

                     

                    EDIT:

                     

                    Doh, ofcourse, it is the _osmf.media - making it look like this:

                     

                    function destroy():void {

                         _osmf.mediaPlayer.stop();

                         _osmf.mediaContainer.removeMediaElement(_osmf.media);

                     

                         _osmf.mediaPlayer.media = null;

                         _osmf.resource = null;

                         _osmf.media = null;   
                         removeChild(
                    _osmf);   
                        
                    _osmf = null;

                    }