I've been wrecking my brain over this problem for two days now, and I have found no solution yet. perhaps some of you actionscript experts here can help

I am making an application where I load a picture from the web at a rate of once per second. When I load a new picture I unload the old one

the problem is that the old pictures are never completely erased from memory and the application keeps on consuming more and more memory until I'm guessing it eats all the memory in the cache (I haven't run it for that long yet :))

here is the code:
what this does is load a picture when you click the screen, then unloads it when you click the picture. do it a few times and notice that the numbers (which show System.totalMemory) only go up but never go down to their original amount...

You can copy and paste this code into flash 9

Code:
var url:String = "http://www.memorycity.com/shop/MBB/images/GIGABYTE_memory.jpg";

stage.addEventListener(MouseEvent.CLICK,onclick)

var txt:TextField = new TextField()
txt.x=10
txt.y=10
txt.width = 400
txt.height = 20

addChild(txt)

var txt2:TextField = new TextField()
txt2.x=300
txt2.y=10
txt2.width = 400
txt2.height = 20

addChild(txt2)

txt2.text = "click to load picture"

function onclick(e:MouseEvent){
	if(e.target==stage)
	loadPic()
}
function loadPic(){
	 var loader:Loader = new Loader();
	loader.addEventListener(MouseEvent.CLICK, clickHandler);

	var request:URLRequest = new URLRequest(url);
	loader.load(request);

	addChild(loader);
	
	//bring texts to front
	removeChild(txt)
	addChild(txt)
	
	removeChild(txt2)
	addChild(txt2)
	txt2.text = "click to unload picture"
}
function clickHandler(event:MouseEvent):void {
	var loader:Loader = Loader(event.target);
	loader.content.bitmapData.dispose()
	removeChild(loader)
	loader.unload();
	loader=null
	txt2.text = "click to load picture"
}

addEventListener(Event.ENTER_FRAME,enterframe)
function enterframe(e:Event){
	txt.text = "total memory: " + System.totalMemory/10000
}