Jump to content
Search Community

Memory leak when using VideoLoader?

jonespeople test
Moderator Tag

Recommended Posts

Hello guys, I've started using Greensock recently, specially TweenLite, it's such an amazing tool!

Now I'm trying to use VideoLoader in an AIR app, to load some videos locally and play them one after another automatically. In order to keep memory as lower as possible, I load each video on its turn and unload them when they're not in use anymore. Even tough I cared for disposals and listener removals, I still have memory rising about 1.6Mb per hour (I've monitored it through Windows 8 Task Manager for almost 10 hours). The videos I've been using are three .flv files. I've tried to search a similar case on the forums, but couldn't find.

 

Does anyone have a clue about what might be the cause of this memory leak? Am I correct to consider this memory I'm tracking as a valid memory leak indicator?

 

Here is my code:
 

package {
	
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.VideoLoader;
	import com.greensock.TweenLite;
	import flash.display.MovieClip;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.filesystem.File;
	import flash.system.System;
	
	public class Main extends MovieClip {
		var paths:Array = [];//to store video files paths
		var vl:VideoLoader;
		var currentVideo:int = -1;
		
		public function Main() {
			if(stage == null) {
				this.addEventListener(Event.ADDED_TO_STAGE, init);
			} else {
				init();
			}
		}

		public function init(e:Event = null) {
			this.removeEventListener(Event.ADDED_TO_STAGE, init);
			
			stage.displayState = StageDisplayState.FULL_SCREEN;
			
			compoundPlaylist();
		}

		function compoundPlaylist() {
			var fileList:Array = File.documentsDirectory.resolvePath("videofolder").getDirectoryListing();
			var ext:String;
			
			//filter for .flv and .f4v files
			for (var i:int = 0;i<fileList.length;i++) {
				ext = fileList[i].extension.toLowerCase();
				if(ext == "flv" || ext == "f4v") {
					paths.push(fileList[i].url);
				}
			}
			
			if(paths.length > 0) {
				loadVideo();//
			} else {
				trace("There are no videos in the specified folder");
			}
		}
		
		function loadVideo() {
			try {
				vl.dispose(true);
			} catch(err:Error){}
			vl = null;
			
			currentVideo++;
			if(currentVideo == paths.length) currentVideo = 0;
			
			vl = new VideoLoader(paths[currentVideo], { container:this, onComplete:playVideo } );
			vl.load();
		}
		
		function playVideo(e:LoaderEvent) {
			vl.content.width = 1280;//change this number according to your screen resolution
			vl.content.height = 768;//change this number according to your screen resolution
			vl.addEventListener(VideoLoader.VIDEO_COMPLETE, wait);
			vl.playVideo();
		}
		
		function wait(e:LoaderEvent) {
			e.target.removeEventListener(VideoLoader.VIDEO_COMPLETE, wait);
			TweenLite.delayedCall(5,loadVideo);
		}
	}
}

Thanks!

Link to comment
Share on other sites

Cheers, Jack.

 

I did what you said, put removeChild(vl.content) before dispose and also tried with different sets of video files, both .flv and .f4v, but no success, memory is still growing.

 

I'll try to run it on other OS. Any other suggestions on how to fix this?

 

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Hey mate,

 

Do you know what phase the memory leak occurs? Like before loading the list of file, after loading, before playing the first video, after playing a couple of videos. Maybe setup a few road blocks and test gradually?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...