Best practices for using .load() and .unload() in regards to memory usage...
Hi,
I'm struggling to understand this, so I'm hoping someone can explain how to further enhance the functionality of my simple unload function, or maybe just point out some best practices in unloading external content.
The scenario is that I'm loading and unloading external swfs into my movie(many, many times over) In order to load my external content, I am doing the following:
Declare global loader:
var assetLdr:Loader = new Loader();Load the content using this function:
function loadAsset(evt:String):void{
var assetName:String = evt;
if (assetName != null){
assetLdr = new Loader();
var assetURL:String = assetName;
var assetURLReq:URLRequest = new URLRequest(assetURL);
assetLdr.load(assetURLReq);
assetLdr.contentLoaderInfo.addEventListener( Event.INIT , loaded)
assetLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, displayAssetLoaderProgress);
function loaded(event:Event):void {
var targetLoader:Loader = Loader(event.target.loader);
assetWindow.addChild(targetLoader);
}
}
}
Unload the content using this function:
function unloadAsset(evt:Loader) {
trace("UNLOADED!");
evt.unload();
}
Do the unload by calling the function via:
unloadAsset(assetLdr)
This all seems to work pretty well, but at the same time I am suspicious that the content is not truly unloaded, and some reminents of my previously loaded content is still consuming memory. Per my load and unload function, can anyone suggest any tips, tricks or pointers on what to add to my unload function to reallocate the consumed memory better than how I'm doing it right now, or how to make this function more efficient at clearing the memory?
Thanks,
~Chipleh