RTMP memory leak on deployed AIR applications?
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);
}
}
}
}
