Adobe Air AS3,如何关闭窗口?分析器建议处理库代码。

4

我的应用程序创建了一个带有几个分组的窗口。当窗口关闭时,窗口及其子元素不会被 GC 回收。

Flash Builder Profiler 帮助我找到并删除事件侦听器,但在事件侦听器添加自 Window.as 库代码后,我已经无法发现问题所在。

具体来说,在窗口打开前和关闭后比较悬空对象,并选择 MyWin 类(1 个实例):

MyPackageName.MyWin(10 条路径)

10 倍下面这行:

Function [savedThis] 569222 GCRoot:Yes bytes:308

单击方法面板中的每个“Function”,我会看到以下 10 个内容位于每个“Function”的顶部:

spark.components:Window:creationCompleteHandler()    Window.as line 2610
spark.components:Window:creationCompleteHandler()    Window.as line 2613
spark.components:Window:creationCompleteHandler()    Window.as line 2616
spark.components:Window:creationCompleteHandler()    Window.as line 2619
spark.components:Window:creationCompleteHandler()    Window.as line 2625
spark.components:Window:creationCompleteHandler()    Window.as line 2639
spark.components:Window:creationCompleteHandler()    Window.as line 2636
Spark.components.supportClasses:SkinnableComponent:attachSkin() SkinnableComponent.as line 694
Spark.components:SkinnableContainer:partAdded()      SkinnableContainter.as line 959
Spark.components:SkinnableContainer:partAdded()      SkinnableContainter.as line 957

所有这些都是以某种方式从MyWin.initialize()中调用的。

我已经删除了代码创建的每个事件监听器,并删除了所有过渡效果,但仍然无法弄清楚它的含义以及如何处理窗口。任何帮助都将不胜感激,因为我已经苦苦挣扎了几天。

2个回答

1
You can try to use 

    System.pauseForGCIfCollectionImminent(1)

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/System.html#pauseForGCIfCollectionImminent%28%29

or try to use 

    System.gc() 

in this way

   private var numCollected; uint = 0;

   private function gCollect(): void
   {
       addEventListeners(Event.ENTER_FRAME, onEFGCollect);
   }

   private function onEFGCollect(event: Event): void
   {
     numCollected++;
     System.gc();
     if(numCollected > 2)
         removeEventListeners(Event.ENTER_FRAME, onEFGCollect);
   }

我们在两个不同的框架中使用System.gc()两次,只是为了收集对象,需要将所有对象标记为已收集 - 只有在这之后,System.gc()才能收集对象。


0
据我所知,最好的方法是确保所有涉及到该窗口的引用都被设置为null。我之前也研究过这个问题,但并没有找到任何直接让垃圾回收器立即工作的方法。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接