Garbage Collection in Flash Player
I build a simple Flex view state based video application on Flash Builder 4.5. There are 4 states. Everytime I go from State1->State2->State3 or State1->State2->State4, the memory in internet explorer increases, but is not released. What am I not deallocating?
Do i have to manually deallocate every single element and its event listeners for each 开发者_JAVA技巧state?
I have version Flash Player 10,2,153,1 installed.
Source Code download is here if you want to build the app and run.
here's the core code:
<?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"
width.State1="1024" height.State1="768"
width.State2="1024" height.State2="768"
width.State3="1024" height.State3="768"
width.State4="1024" height.State4="768">
<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
currentState='State2';
}
protected function button2_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
currentState='State3';
}
protected function button3_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
currentState='State1';
}
protected function button4_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
currentState='State2';
}
protected function button5_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
currentState='State4';
}
]]>
</fx:Script>
<s:states>
<s:State name="State1" />
<s:State name="State2"/>
<s:State name="State3"/>
<s:State name="State4"/>
</s:states>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button includeIn="State1" x="405" y="175" width="227" height="73" label="Music List"
click="button1_clickHandler(event)" fontSize="30" itemDestructionPolicy="auto" />
<s:Label includeIn="State1" x="440" y="61" fontSize="30" text="Main State" itemDestructionPolicy="auto"/>
<s:Label includeIn="State2" x="409" y="34" fontSize="30" text="Classical Video" itemDestructionPolicy="auto"/>
<s:Button includeIn="State2" x="328" y="151" width="369" height="91"
label="Beethoven - "Für Elise"" click="button2_clickHandler(event)"
fontSize="30"
itemDestructionPolicy="auto"
/>
<s:VideoPlayer includeIn="State3,State4" x="0" y="67" width="1024" height="530" autoPlay="false"
loop="true" scaleMode="stretch" source="assets/Beethoven__Für_Elise.mp4"
source.State4="assets/FOUR_SEASONS_VIVALDI_LANDSCAPES_AND_MUSIC.mp4"
itemDestructionPolicy="auto"
/>
<s:Button includeIn="State3,State4" x="2" y="14" width="240" height="45" label="Return to Main"
click="button3_clickHandler(event)" fontSize="30"
itemDestructionPolicy="auto"
/>
<s:Button includeIn="State3,State4" x="338" y="629" width="348" height="63" label="Return to classical"
click="button4_clickHandler(event)" fontSize="30"
itemDestructionPolicy="auto"
/>
<s:Button includeIn="State2" x="326" y="287" width="371" height="81"
label="Vivaldi – “Four Seasons”" click="button5_clickHandler(event)" fontSize="30"
itemDestructionPolicy="auto"
/>
</s:Application>
View from the detecting loitering objects(http://help.adobe.com/en_US/flashbuilder/using/WSe4e4b720da9dedb5510654d812e4d126514-8000.html#WS6f97d7caa66ef6eb1e63e3d11b6c4d0d21-7ee8) is here
View from the object references(http://help.adobe.com/en_US/flashbuilder/using/WSe4e4b720da9dedb5510654d812e4d126514-8000.html#WS6f97d7caa66ef6eb1e63e3d11b6c4d0d21-7eef) from the topmost Object in the 'loitering objects view' is here
I checked the documentation for "Controlling caching of objects created in a view state" and set the itemDestructionPolicy="auto". It still is caching the objects and memory is not being released as seen in the Task Manager.
精彩评论