0

我们有包含许多 ItemRenderer 的 Spark dataGrid。我们每次加载超过 200 行。这会导致我们的应用程序发生内存泄漏。那么有什么方法可以释放 ItemRenderers 吗?

分析时问题几乎与此相似

实例不断增加,我使用 arrayCollection 作为数据提供者。我什至调用 dataprovider (arrayCollection) .removeAll() 并且显示变为空白,但 itemRenderer 的实例数并没有下降。然后我在分析器中运行垃圾收集器,项目渲染器仍然保留在内存中。如何从内存中删除 itemRenderers?

4

1 回答 1

0

make sure your item renderers do not use event handlers in the mxml, as mxml event handlers do not use weak references and thus never get GCed.

For example: I had an itemrenderer component in mxml that looked like <s:ItemRenderer creationComplete="OnCreationComplete">

instead I created a base class: public class ItemRendererBase extends ItemRenderer and in the constructor added the event listener this.addEventListener(FlexEvent.CreationComplete, OnCreationComplete, false, 0, true)

for sub component event handlers such as <s:Button click="OnClickButton"/> remove the inline event wiring and instead wire the event handler in your override OnCreationComplete with false, 0, true to use a weak reference.

also make sure you manually invoke the GC collection for testing this and I recomend using adobe scout

于 2020-11-05T21:38:12.587 回答