1 Reply Latest reply on Sep 20, 2011 3:29 AM by S_Aleksey

    s:VideoDisplay and mx:VideoDisplay memory leaks

    S_Aleksey Level 1

      I have created very simple example which basically just changes source property of VideoDisplay object on timer. Here is the code:

      <?xml version="1.0" encoding="utf-8"?>

      <s:WindowedApplication creationComplete="creationComplete(event)" xmlns:fx="http://ns.adobe.com/mxml/2009"

                                                           xmlns:s="library://ns.adobe.com/flex/spark"

                                                           xmlns:mx="library://ns.adobe.com/flex/mx">

                <fx:Script>

                          <![CDATA[

                                    import mx.events.FlexEvent;

       

       

                                    protected function creationComplete(event:FlexEvent):void

                                    {

                                              var timer:Timer = new Timer(1000);

                                              timer.addEventListener(TimerEvent.TIMER, onTimer);

                                              timer.start();

                                    }

       

                                    private function onTimer(event:Event):void

                                    {

                                              videoDisplay.source = null;

                                              videoDisplay.source = "file:///D:\\test.flv";

                                    }

       

                          ]]>

                </fx:Script>

                <s:VideoDisplay id="videoDisplay"/>

      </s:WindowedApplication>

       

      When I launch this example it works for several seconds and then it crashes(Flex Debugger crashes too) and the reason is memory leak. On each set of source property memory just adds up and it is never released.

      If I replace "<s:VideoDisplay id="videoDisplay"/>" with "<mx:VideoDisplay id="videoDisplay"/>" it works fine. Memory is correctly released an there is no crash.

       

      Hovewer if I make simple modification where I create new instance of mx:VideoPlayer on timer and remove previous instance  on timer I  get memory leak. It is not so large as in example with s:VideoDisplay but after several minutes of work application crashes. Here is the code:

      <?xml version="1.0" encoding="utf-8"?>

      <s:WindowedApplication creationComplete="creationComplete(event)" xmlns:fx="http://ns.adobe.com/mxml/2009"

                                                           xmlns:s="library://ns.adobe.com/flex/spark"

                                                           xmlns:mx="library://ns.adobe.com/flex/mx">

                <fx:Script>

                          <![CDATA[

                                    import mx.controls.VideoDisplay;

                                    import mx.events.FlexEvent;

       

       

                                    protected function creationComplete(event:FlexEvent):void

                                    {

                                              var timer:Timer = new Timer(1000);

                                              timer.addEventListener(TimerEvent.TIMER, onTimer);

                                              timer.start();

                                    }

       

                                    private var videoDisplay:VideoDisplay;

       

                                    private function onTimer(event:Event):void

                                    {

                                              if(videoDisplay)

                                              {

                                                        videoDisplay.stop();

                                                        videoDisplay.close();

                                                        videoDisplay.source = null;

                                                        removeElement(videoDisplay);

                                                        videoDisplay = null;

                                              }

                                              if(videoDisplay == null)

                                              {

                                                        videoDisplay = new VideoDisplay();

                                                        videoDisplay.source = "file:///D:\\test.flv";

                                                        addElement(videoDisplay);

                                              }

                                    }

       

                          ]]>

                </fx:Script>

      </s:WindowedApplication>

       

       

       

      Can someone please let me know what I am doing wrong? Any additional functions I need to call to cleanup memory correctly? Any workarounds?

       

      Best Regards, Aleksey