Memory leaks flashplayer中的垃圾收集

Memory leaks flashplayer中的垃圾收集,memory-leaks,flex4,mxml,flash-builder4.5,Memory Leaks,Flex4,Mxml,Flash Builder4.5,我在FlashBuilder4.5上构建了一个简单的基于FlexView状态的视频应用程序。有4个州。每次我从State1->State2->State3或State1->State2->State4开始,internet explorer中的内存都会增加,但不会释放。我没有放弃什么 我是否必须为每个状态手动取消分配每个元素及其事件侦听器 我安装了Flash Player 10,2153,1版 如果您想构建应用程序并运行,请下载源代码 以下是核心代码: <?xml version="1.0

我在FlashBuilder4.5上构建了一个简单的基于FlexView状态的视频应用程序。有4个州。每次我从State1->State2->State3或State1->State2->State4开始,internet explorer中的内存都会增加,但不会释放。我没有放弃什么

我是否必须为每个状态手动取消分配每个元素及其事件侦听器

我安装了Flash Player 10,2153,1版

如果您想构建应用程序并运行,请下载源代码

以下是核心代码:

<?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 - &quot;Für Elise&quot;" 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>

此处是检测游荡对象()的视图

“游荡对象视图”中最顶层对象的对象引用视图()位于此处


我检查了文档中的“”并设置itemDestructionPolicy=“auto”。它仍然在缓存对象,并且内存没有像任务管理器中显示的那样被释放。

它是否在不断增加?比如,如果你经常改变状态,它就不会被收集,或者只是通过这些状态。GC不会运行,除非它需要运行,而强制它运行的是当需要分配更多的对象时,它应该清理内存。它不会不断增加,这是一个严重的内存泄漏。只有当您通过交互频繁地更改状态时,才会发生这种情况。GC何时以什么限制运行?这里是指向flex的GC的链接。基本上,它会在需要的时候运行,我发现有时候这意味着当它接近程序允许的最大内存时,它会在分配新对象时执行大量的垃圾收集;新的链接是。最引人注目的是“因此,当您删除对某个对象的所有引用时,垃圾收集器不一定会释放该对象的内存。该对象将成为垃圾收集的候选对象。”例如,在1 GB的计算机上,GC何时启动?如果您在使用应用程序时观察分析器,您应该能够看到它的发生。我个人对它的内部结构不太了解,但从我自己的研究中收集到的信息来看,它基本上会在实际执行收集之前使用尽可能多的内存。正如您所指出的,删除对对象的所有引用使其成为GC的候选对象,因为收集器仅在新对象需要内存时运行,GC将清理足够的候选对象以创建所需的空间。还要注意的是:您不能通过编程在代码中强制使用GC。