a.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"
layout="absolute" width="400" height="300">
<mx:Text text="aaaaaaaaaaaaaaaaaaaa"/>
</mx:Module>
b.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"
layout="absolute" width="400" height="300">
<mx:Text text="bbbbbbbbbbbbbbbbbbbbbbbb"/>
</mx:Module>
Test.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.modules.ModuleLoader;
private var i:int = 0;
protected function button1_clickHandler(event:MouseEvent):void {
i++;
var loader:ModuleLoader = new ModuleLoader;
loader.applicationDomain = ApplicationDomain.currentDomain;
loader.url = i % 2 == 0 ? 'b.swf' : 'a.swf';
if (mainContainer.numChildren > 0) {
loader.applicationDomain = null;
ModuleLoader(mainContainer.getChildAt(0)).url = null;
}
mainContainer.removeAllChildren();
mainContainer.addChild(loader);
System.gc()
trace(System.totalMemory)
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<mx:Canvas id="mainContainer" height="80%" width="100%"/>
<s:Button click="button1_clickHandler(event)"/>
</s:Application>
打印的信息是
[SWF] //Test.swf/[[DYNAMIC]]/1 - 解压缩后为 650,777 个字节
[SWF] //Test.swf - 解压缩后为 244,086 个字节
[SWF] //Test.swf/[[DYNAMIC]]/2 - 解压缩后为 370,463 个字节
[SWF] //Test.swf/[[DYNAMIC]]/3 - 解压缩后为 2,311,734 个字节
[SWF] //Test.swf/[[DYNAMIC]]/4 - 解压缩后为 1,432,382 个字节
[SWF] //Test.swf/[[DYNAMIC]]/5 - 解压缩后为 323,354 个字节
[SWF] //Test.swf/[[DYNAMIC]]/6 - 解压缩后为 441,362 个字节
28311552
[SWF] //a.swf - 解压缩后为 210,261 个字节
33742848
[SWF] //b.swf - 解压缩后为 210,265 个字节
30629888
[卸装 SWF] //b.swf
[SWF] //a.swf - 解压缩后为 210,261 个字节
30588928
[SWF] //b.swf - 解压缩后为 210,265 个字节
32129024
[卸装 SWF] //b.swf
[SWF] //a.swf - 解压缩后为 210,261 个字节
32133120
31395840
31170560
31174656
[SWF] //a.swf - 解压缩后为 210,261 个字节
32018432
31944704
[SWF] //a.swf - 解压缩后为 210,261 个字节
33374208
[卸装 SWF] //a.swf
[卸装 SWF] //a.swf
[SWF] //b.swf - 解压缩后为 210,265 个字节
问题1:Test.swf为什么打印了多次?是加载了多次吗?
问题2:swf有卸载,但System.totalMemory为什么总是增加?