Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-11-2010, 03:39 PM   #1
Registered User
Join Date: Apr 2010
Posts: 4
Default Video player memory leak help?

Hey guys,

I'm trying to create a video player app which gets its playlist from an external xml and its going well but I'm getting some serious memory leaks.

Here is my xml playlist:

HTML Code:
<?xml version="1.0" encoding="utf-8"?>
	<mp4 label="TestMovie1.mp4" icon="myMovieIcon" />
	<mp4 label="TestMovie2.mp4" icon="myMovieIcon" />
	<mp4 label="TestMovie3.mp4" icon="myMovieIcon" />
	<mp4 label="TestMovie4.mp4" icon="myMovieIcon" />
My main code:
ActionScript Code:
import flash.events.Event;             [Bindable] public var playlist:String; //"region1"             [Bindable] public var currentItem:Number = 0;             private var dataXML:XML; private var contentList:Array = new Array(); private var workDir:String = "c:/temp/"; private function loadXml():void {     var loader:URLLoader = new URLLoader(new URLRequest(workDir + playlist + ".xml"));     loader.addEventListener("complete", parseXml); }             private function parseXml(e:Event):void {     dataXML = XML(e.target.data);     var listLength:Number = dataXML.children().length();     for(var i:Number = 0; i<listLength; i++)         {         contentList.push(dataXML.children()[i]..@label);     }                     nextItem(); }                 private function nextItem():void {     var dataFile:File = new File(workDir + contentList[currentItem]);                     if(dataFile.exists)     {         if(dataFile.extension == "mp4" || dataFile.extension == "flv")         {             var vp:videoPlayer = new videoPlayer();                                     this.addElement(vp);             vp.addEventListener(Event.COMPLETE, movieDone);             vp.x = 0;                  vp.y = 0;             vp.width = this.width;             vp.height = this.height;             vp.vidName = workDir + contentList[currentItem];             vp.vidWidth = vp.width;             vp.vidHeight = vp.height;             vp.vidDis.scaleMode = "letterbox";         }     }     else     {         trace(contentList[currentItem] + " can't be located");     }                 }             public function movieDone(e:Event):void {     this.removeAllElements();             if(currentItem == contentList.length -1)     {         currentItem = 0;         nextItem();     }     else     {         currentItem = currentItem + 1;         nextItem();     } }

And the videoPlayer component:
		[Event(name="complete", type="flash.events.Event")]
ActionScript Code:
import org.osmf.events.TimeEvent;                         [Bindable]             public var vidName:String;             [Bindable]             public var vidWidth:Number;             [Bindable]             public var vidHeight:Number;                         protected function videoplayer1_completeHandler(event:TimeEvent):void             {                 var e:Event = new Event("complete");                 dispatchEvent(e);             }
]]> </fx:Script> <mx:Container x="0" y="0" width="{vidWidth}" height="{vidHeight}" backgroundColor="#000000"> <s:VideoDisplay id="vidDis" x="0" y="0" width="{vidWidth}" height="{vidHeight}" source="{vidName}" complete="videoplayer1_completeHandler(event)" chromeColor="#000000"/> </mx:Container> </s:Group>
So I create the videoPlayer component and pass in the mp4 file from an array. Once the video is complete it dispatches a custom event which runs the movieDone function. I call the this.removeAllElements() to remove the videoPlayer component before adding it again. I am very new at this but it doesnt seem like the video is being removed as the physical memory climbs with each new video, and eventually after several loops the program will crash. Anyone know what I'm doing wrong?
Dholem is offline   Reply With Quote
Old 11-11-2010, 07:24 PM   #2
tadster's Avatar
Join Date: Feb 2009
Location: Texas
Posts: 2,111

what about the Array are you clearing that?


wait, I think you should be able to do it without re-instantiating the videoPlayer every time. That's what is building up, even when you remove it, you need to only call
new videoPlayer(); once, preferably in a constructor.
www.actiontad.com - ActionScript and JavaScript sitting in a tree...

Last edited by tadster; 11-11-2010 at 07:28 PM.
tadster is offline   Reply With Quote
Old 04-21-2011, 12:55 PM   #3
Registered User
Join Date: May 2009
Posts: 4

I think you cant load file directly (sandbox limitation) from the file system, except when creating a AIR application.
daslicht is offline   Reply With Quote
Old 04-22-2011, 01:12 AM   #4
drkstr's Avatar
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587

I 2nd Tadster. You want to swap your video source, not your video player.
drkstr is offline   Reply With Quote
Old 04-29-2011, 11:15 AM   #5
Join Date: Feb 2009
Posts: 68

I don't think you can memory leak in actionscript
cpthk is offline   Reply With Quote
Old 04-29-2011, 02:48 PM   #6
drkstr's Avatar
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587

Originally Posted by cpthk View Post
I don't think you can memory leak in actionscript
You most certainly can. Any object that still has a reference to it will never be garbage collected. The most common cause of this is failing to remove event listeners.
drkstr is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 01:44 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.