Jump to content
Search Community

Best practices for adding and removing Loaders (memory build up)

Multi-Task test
Moderator Tag

Recommended Posts

Good morning, 

I am trying to create a little toy where I can loop FLVs and SWFs.  What are the best practices for this when it comes to adding and removing them from the display list?

 

I tried running this for a few hours and noticed that the memory continued to build.  I am using the XMLLoader and then using LoaderMax to handle rest.  Everything plays fine for the most part and files get added and removed however the memory building is where I am boggled.  

 

Below is how I am going about adding and removing items from the display, as well as, managing playback.

private function  managePlayBack():void {
	//if list is complete
	if(mediaTracker==(media.numChildren)) {
		//setTracker back to 0
		mediaTracker=0;
		managePlayer();
	} else {
		mediaTracker++;
		managePlayer();
	}
}


private function  managePlayer():void {
	var currAsset = media.getChildAt(mediaTracker);
	if(currAsset.vars.type!=null) {
		//detect what type of asset needs to be shown and played
		if(currAsset is VideoLoader){
		container_mc.addChild(currAsset.content);
		currAsset.playVideo();
		currAsset.addEventListener(VideoLoader.VIDEO_COMPLETE, videoComplete);
		}    
					
		if(currAsset is SWFLoader){
		container_mc.addChild(currAsset.rawContent);
		currAsset.rawContent.gotoAndPlay(1);
		addEventListener(Event.ENTER_FRAME, swfComplete);
		}
	}
	currAsset = null;
}


/* VIDEO  COMPLETE FUNC */
private function  videoComplete(e:Event):void {
	var currAsset:VideoLoader = VideoLoader(e.target);
	currAsset.removeEventListener(VideoLoader.VIDEO_COMPLETE, videoComplete);
	currAsset.gotoVideoTime(0, false);
	container_mc.removeChildAt(0);
	currAsset=null;
	//set up and play the next asset
	managePlayBack();
}
		
/* SWF COMPLETE FUNC */
private function  swfComplete(e:Event):void {
	var currAsset = media.getChildAt(mediaTracker);
	if (currAsset.rawContent.currentFrame == currAsset.rawContent.totalFrames) {
		removeEventListener(Event.ENTER_FRAME, swfComplete);
		currAsset.content.visible = false;
		currAsset.rawContent.gotoAndStop(1);
		container_mc.removeChildAt(0);
		currAsset=null;
		//set up and play the next asset
		managePlayBack();
	}
}

Thanks in advance for any insight on this.

 

-MT

Link to comment
Share on other sites

Thanks Carl.  Even if I am going to cycle through and play them again?  I thought the dispose method completely removes them and sets it out for GC...

 

It is fairly odd too, since I am testing also if all eventListeners have been cleared which they are.  Like so, 

trace(currAsset.hasEventListener(VideoLoader.VIDEO_COMPLETE));

Returns false as it should.

Link to comment
Share on other sites

Sorry, I mis-read your question.

 

If you want to re-use them later, then don't dispose() them. Removing them from the display list should suffice and memory build up should not occur if you aren't loading new assets. 

 

I'd suggest trying using ONLY SWFLoaders or ONLY VideoLoaders to see if perhaps one type of asset is causing the problem. My gut feeling is that the flvs might be the issue as Adobe's NetStream class has a horrendous track record of bugs (bottom of page).

 

From looking at your code, there really isn't anything that jumps out at me as being the cause of a memory leak. It looks quite good.

  • Like 1
Link to comment
Share on other sites

Roger that Carl.  A new test will commence here shortly.  I will try swfs only (without FLVs embedded).  Thanks for the help, forgot to mention this is for an air app.  no browser.

 

Interesting comment you made about FLVs.  I have a few SWFs that have FLVs embedded in them and they act very goofy upon playback.  

 

I'll be back (arnold voice).

 

Thanks again.

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...