Skip to main content
Participating Frequently
March 29, 2013
Question

RTMP memory leak on deployed AIR applications?

  • March 29, 2013
  • 1 reply
  • 1581 views

Hi,

I am building a simple AIR application for personal use which plays a live RTMP stream. While building an AIR package and running the application for long time, I noticed that there was a memory leak with the application which eventually crashes it. The code is very simple... and could not figure out where the leak is coming from. Maybe this is a AIR runtime bug? If anyone has any clue, please help me out!

The codes is as below:

package

{

          import flash.display.Sprite;

          import flash.display.StageAlign;

          import flash.display.StageScaleMode;

          import flash.events.Event;

          import flash.events.NetStatusEvent;

          import flash.events.TimerEvent;

          import flash.media.Video;

          import flash.net.NetConnection;

          import flash.net.NetStream;

          import flash.net.URLLoader;

          import flash.net.URLRequest;

          import flash.system.System;

          import flash.utils.Timer;

          [SWF(backgroundColor="#0", frameRate="60", width="1920", height="1080")]

          public class KBSStreamTest extends Sprite

          {

                    private var _dataLoader:URLLoader;

                    private var _video:Video;

                    private var _nc:NetConnection;

                    private var _ns:NetStream;

                    private var _playing:Boolean;

                    public function KBSStreamTest()

                    {

                              stage.scaleMode = StageScaleMode.NO_SCALE;

                              stage.align = StageAlign.TOP_LEFT;

                              _nc = new NetConnection();

                              _nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

                              _video = new Video(1920, 1080);

                              _video.smoothing = true;

                              addChild(_video);

                              _video.attachNetStream(_ns);

                              getData();

                              var t:Timer = new Timer(1000);

                              t.start();

                              t.addEventListener(TimerEvent.TIMER, gc);

                    }

                    private function gc(event:TimerEvent):void

                    {

                              System.gc();

                    }

                    private function getData():void

                    {

                              if (_dataLoader)

                              {

                                        _dataLoader = null;

                                        _dataLoader.removeEventListener(Event.COMPLETE, onDataLoadComplete);

                              }

                              _dataLoader = new URLLoader();

                              _dataLoader.load(new URLRequest("http://k.kbs.co.kr/KplayerWCFService/KplayerRest.svc/json/GetLiveChannelStreamURLSSO/11/0"));

                              _dataLoader.addEventListener(Event.COMPLETE, onDataLoadComplete);

                    }

                    private function onDataLoadComplete(event:Event):void

                    {

                              openStream(JSON.parse(_dataLoader.data).StreamItemWithURL.AUTHSTREAMURL);

                    }

                    private function openStream(url:String):void

                    {

                              _nc.connect(url);

                    }

                    private function onNetStatus(event:NetStatusEvent):void

                    {

                              trace("::: netStatus", event.info.code);

                              switch (event.info.code)

                              {

                                        case "NetConnection.Connect.Success":

                                                  trace("connection success");

                                                  _ns = new NetStream(_nc);

                                                  _ns.client = this;

                                                  _ns.play("");

                                                  _video.attachNetStream(_ns);

                                                  _playing = true;

                                                  break;

                                        case "NetStream.Play.StreamNotFound":

                                        case "NetConnection.Connect.Rejected":

                                        case "NetConnection.Connect.Failed":

                                        case "NetConnection.Connect.Closed":

                                                  break;

                              }

                    }

                    public function onMetaData(obj:Object = null):void

                    {

                              trace("onMetaData");

                              for (var i:String in obj)

                              {

                                        trace(i, obj);

                              }

                    }

          }

}

This topic has been closed for replies.

1 reply

hoonoAuthor
Participating Frequently
April 1, 2013

I tried with differend version of SDKs and found out that the ADL of AIR 3.1 SDK does not create any issues with memory leaks. However, when packaged as release build, the memory leak problem started again. So I uninstalled the latest version of AIR, which was 3.6 and tried installing 3.1. And then the memory leak disappeared.

Could this be a major bug with AIR runtime? Maybe I should submit this issue to the Adobe bug tracking system..

hoonoAuthor
Participating Frequently
April 1, 2013

Seems to be 3.6 problem. AIR runtime 3.5 seems to run the above code without any memory leak.

chris.campbell
Legend
April 2, 2013

Could you please open a new bug report on this over at bugbase.adobe.com?  When adding the bug, please include sample code or an application so we can quickly test this out internally.

Once added, please post back with the URL so that others affected can add their comments and votes.   I'd also like to follow up with this internally.

Thanks,

Chris