I found a solution. I tried removing all the UIComponents and still had the issue with the shell retaining 2/3 of each loaded module. So this led me to believe it is not a UIComponent issue even though the Flex profiler shows a [listener0] as the cause. I decided to take another look at a similar project (
http://www.nutrixinteractive.com/blog/?p=132&cpage=1#comment-30581) claiming to be able to recover all the memory after the first module load, so from the second module on.
According to Cliff and Adobe "When a module is loaded by the Flex application for the first time, the module’s SWF file is transferred across the network and stored in the browser’s cache. If the Flex application unloads that module, but then later reloads it, there should be less wait time because Flash Player loads the module from the cache rather than across the network.
So, although Flex GC may have released its reference to the loaded module, it will still consume system memory until the browser has flushed its cache. This is seen as a positive thing from a reuse standpoint if you create more instances later, but may not be what you want if you’ve loaded a huge module, only want to use it once and then wish to get rid of it altogether. That might actually require talking to some external JavaScript in the browser to tell it to flush its cache. I don’t even know if that’s possible. But it does explain why sometimes after loading and unloading a module, you still see some memory gone missing."
Any way I digress. The trick is the location of removeChild. I commented out the prior location..
var moduleName:String = getModuleName(moduleID
);
//application.removeChild(application.getChildByName(moduleName));
loaderDict.content.fabricator.dispose();
loaderDict.content.dispose();
loaderDict.unloadAndStop(true);
delete(loaderDict);
startGCCycle();
application.removeChild(application.getChildByName(moduleName));
And it worked. Before the shell's memory usage would grow after every module load/unload now after the first module it grows by 2/3 and everything else after that is fully recovered. I believe that display objects need to be on stage for the event cycles to run or even be removed properly.
I will try to post my examples soon.
Greg