Flex使用0路径游荡对象 [英] Flex loitering objects with 0 paths

查看:127
本文介绍了Flex使用0路径游荡对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在泄漏一个名为GraphViewer的可视化组件。每当用户更改图形时,都会创建一个新的查看器,并将旧的查看器从舞台上移除并丢弃。然而记忆似乎在泄漏。当我使用Flex Profiler跟踪游荡对象时,它显示GraphViewer实例确实泄漏,但是当我检查游荡观察者的对象引用时,我发现所有这些对象(除了一个)都有0根GC路径根目录。



我在GC之后拍一张内存快照,然后更改图形(创建一个新的查看器)N次。然后我做GC,再拍快照,看看游荡的物体。我看到N个GraphViewer对象正在闲逛,但其中的N-1实际上有0个路径,只有一个实际上引用了它。



为什么Flex剖析器显示对象为游荡何时无法从GC根目录中获取? Flex Profiler是否可靠?

解决方案

首先,当新数据到达时,为什么需要创建组件的新实例?似乎有点浪费。第二,在没有代码的情况下很难回答你的问题,但是通常情况下,视图组件保存的原因在内存中是因为某人仍然有一个引用它或一个事件监听器没有被正确清理。

最后,有一个已知的错误在GC一段时间以来(尽管我最近还没有测试过;大概一年后,我可以重现),大的内存岛(想象一个非常大的模块)将不能正确地清理,因为往返算法GC不会认为它和其他的没有关系。为了减轻这一点,你可能需要实现一个IDisposable接口,其中你的父视图调用一个销毁函数,然后从阶段中移除(然后传播到整个组件,它的孩子也销毁)。

祝你好运。

My application is leaking a visual component called GraphViewer. Every time the user changes graphs a new viewer is created and the old one is removed from the stage and discarded. Yet memory seems to leak. When I use the Flex profiler to track loitering objects it shows that GraphViewer instances indeed leak, but when I examine the object references of the loitering viewers I see that all of them (except one) have 0 paths to GC root.

I take a memory snapshot after GC and then change the graph (create a new viewer) N times. Then I do GC, take another snapshot and look at loitering objects. I see N GraphViewer objects loitering, but N-1 of them actually have 0 paths and only one has anything actually referencing it.

Why is the Flex profiler showing objects as loitering when they cannot be reached from the GC root? Is the Flex profiler reliable?

解决方案

First off, why do you need to create a new instance of your component when new data arrives? Seems a bit wasteful. It's better to reuse an instance than to create a new one.

Second, it's hard to answer your issue without code, but often times the reason why a view component is kept in memory is because someone either still have a reference to it or an event listener hasn't been cleaned properly.

And lastly, there has been a known bug in the GC for some time now (though I haven't tested it recently; been about a year since I could reproduce) where large memory 'islands' (think of a very large module) won't clean up properly because the round trip algorithm for the GC won't figure that it's disconnected from the rest. To alleviate that, you might want to implement an IDisposable interface where your 'parent' view calls a destroy function before removing from stage (which then propagates throughout the component and it's children to destroy as well).

Good luck.

这篇关于Flex使用0路径游荡对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆