该应用程序太大,无法在此描述,但我可以告诉您,我有多达 20 个或更多模块可供客户端随时使用。如果我继续加载一个又一个屏幕,我的应用程序可能会占用 500MB 甚至更多。
我用来加载和卸载模块的脚本是:
public function createModule(modulo:String):void {
if(moduleLoader != null){
moduleLoader.unloadModule();
//moduleLoader.url = null;
moduleLoader.url = "com/oss/facturable/components/" + modulo + "?version=" + model.configXML.versionApp;
moduleLoader.loadModule();
}
}
private function errorHandler(e:ModuleEvent):void {
Alert.show("No se ha podido cargar el modulo. Contacte al departamento técnico.");
}
加载模块的容器:
<s:BorderContainer width="98%" height="98%" includeIn="mainState" styleName="bcModuleLoader" top="100">
<s:layout>
<s:HorizontalLayout paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10"/>
</s:layout>
<s:Scroller width="100%" height="100%">
<s:Group>
<mx:ModuleLoader id="moduleLoader" error="errorHandler(event)" width="100%" height="100%" horizontalAlign="center" verticalAlign="top" creationComplete="createModule('bandejaEntrada.swf')"/>
</s:Group>
</s:Scroller>
</s:BorderContainer>
每当我单击我认为与此处发布无关的菜单选项时,都会调用 createModule 函数。总而言之,这就是我现在所拥有的让它工作和泄漏的一切:S
这是官方的unloadModule函数,我想,从它的外观来看,内存应该很好地分配给这个东西,我的意思是,看!它删除所有事件监听器和子对象。为什么我的内存在卸载时保持不变,而当我打开新模块时加载更多内存?!啊啊!
public function unloadModule():void
{
if (child)
{
removeChild(child);
child = null;
}
if (module)
{
module.removeEventListener(ModuleEvent.PROGRESS,
moduleProgressHandler);
module.removeEventListener(ModuleEvent.SETUP, moduleSetupHandler);
module.removeEventListener(ModuleEvent.READY, moduleReadyHandler);
module.removeEventListener(ModuleEvent.ERROR, moduleErrorHandler);
module.unload();
module.removeEventListener(ModuleEvent.UNLOAD, moduleUnloadHandler);
module = null;
}
}