Flash as 3.0 Loader Memory extending

Hi, I have a main file with a loader+ 2 buttons in it which loads & unloads 2 external ".swf" files and a trace to monitor the System.totalMemory. PROBLEM IS after  my unload command the memory dosnot get's free and even increasing on every load then unload command.

var loaderObj:Loader
var sp:Sprite= new Sprite()
 
function mcLoad(e:MouseEvent){	
	loaderObj= new Loader();
	loaderObj.name='tension';
 	var str:String="i.jpeg";
	loaderObj.load(new URLRequest(str));
	sp.addChild(loaderObj);
	stage.addChild(sp)
}
 
function mcUnload(e:MouseEvent){
	loaderObj.unload();
	sp.removeChild(loaderObj);
	stage.removeChild(sp)
	trace(System.totalMemory);
}
 
b0.addEventListener(MouseEvent.CLICK,mcLoad);
b1.addEventListener(MouseEvent.CLICK,mcUnload);

Open in new window

aditkohliAsked:
Who is Participating?
 
asaivanConnect With a Mentor Commented:
try setting sp to null, after you've removed it from the stage.

e.g.

sp = null;
0
 
bridgetimillerCommented:
Try using Loader.unloadAndStop().  This is allow help clear all references to the Loader and make it accessible for garbage collection.
0
 
bridgetimillerConnect With a Mentor Commented:
loaderOjb.unloadAndStop() in your case. :)
0
 
blue-genieConnect With a Mentor Commented:
flash players garbage collection is not as robust as Java or .NET - you can't force it to happen.
by removing item and deleting references you free them up to be garbage collected but it may not happen immediately.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.