Reputation: 23
i have problem with memory usage in flash, I successfully unload and remove loaded SWF's from the stage but i can't remove loaded memory and also the fps is dropping down from 30 to 18.
How i load the SWF in to memory
I loading them like this:
mLoader = new Loader();
var mRequest:URLRequest = new URLRequest(url);
mLoader.load(mRequest);
mLoader.x = pozX;
mLoader.y = pozY;
swfModules[url] = mLoader;
swfUrlArray.push(url);
currentLoaded = url;
addChild(mLoader);
Removing the SWF's in the loop
for(var i=0; i < swfUrlArray.length; i++) {
if(swfModules[swfUrlArray[i]] != null) {
swfModules[swfUrlArray[i]].unloadAndStop();
removeChild(swfModules[swfUrlArray[i]]);
}
swfUrlArray=[];
}
What i suspect here is that loop is too fast to flash to unload the SWF's memory for all files at same time. Please any suggestions or ides for this problem.
Upvotes: 0
Views: 419
Reputation: 4870
You clear the swfUrlArray INSIDE your for loop. So it will only unloadAndStop the first, find that the length of the array is 0 and stop.
Modified code:
for(var i=0; i < swfUrlArray.length; i++) {
if(swfModules[swfUrlArray[i]] != null) {
swfModules[swfUrlArray[i]].unloadAndStop();
removeChild(swfModules[swfUrlArray[i]]);
}
}
swfUrlArray=[];
And do what @alxx says about removing the swf reference from the dictionary.
Upvotes: 1
Reputation: 9897
Is swfModules a Dictionary? It seems it still holds reference for loaded swf. Use delete swfModules[url]
to remove item from Dictionary.
Upvotes: 0