调试 FLEX/AS3 内存泄漏 [英] Debugging FLEX/AS3 memory leaks

查看:27
本文介绍了调试 FLEX/AS3 内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当大的 Flex &Papervision3D 应用程序,可连续创建和销毁对象.它还加载和卸载 SWF 资源文件.当它运行时,SWF 在播放器发出嘶嘶声时会缓慢消耗内存,直到大约 2GB.显然,我很确定我放弃了对不再需要的实例的引用,并期望 GC 能够完成它的工作.但我花了很长时间才弄清楚问题出在哪里.

I have a pretty big Flex & Papervision3D application that creates and destroys objects continually. It also loads and unloads SWF resource files too. While it's running the SWF slowly consumes memory til about 2GB when it croaks the player. Obviously I am pretty sure I let go of reference to instances I no longer want with expectation the GC will do its job. But I am having a heck of a time figuring out where the problem lies.

我已经尝试使用探查器及其选项来捕获内存快照等 - 但我的问题仍然难以解决.我认为使用调试 Flash 播放器也存在已知问题?但我也不喜欢使用发行版.

I've tried using the profiler and its options for capturing memory snapshots, etc - but my problem remains evasive. I think there are known problems using debug Flash player also? But I get no joy using the release version either.

您如何使用 FLEX/AS3 追踪内存泄漏问题?您使用过哪些策略、技巧或工具来定位消费

How do you go about tracking down memory leak problems using FLEX/AS3 ? What are some strategies, tricks, or tools you have used to locate consumption

推荐答案

我偶然发现了一些解释如何在 Flex Builder 中使用 Flex Profiler 的内容,这对我调试内存泄漏有很大帮助.我肯定会建议尝试一下.它非常容易使用.我在分析我的应用程序时发现的一些事情:

I stumbled across something explaining how to use Flex Profiler in Flex Builder and it was a HUGE help to me in debugging memory leaks. I would definitely suggest trying it out. It's very easy to use. Some things I found when profiling my applications:

避免使用集合(至少是大型集合)作为值对象的属性.我的 Cairngorm 应用程序中有几种类型的值对象类,每个类都有一个children"属性,它是一个 ArrayCollection,用于过滤.在分析时,我发现这些是我最大的内存消耗者之一,因此我更改了我的应用程序,将parentId"存储为 int 并将其用于过滤.使用的内存被大幅削减.像这样:

Avoid using collections (at least LARGE collections) as properties of Value Objects. I had several types of Value Object Classes in my Cairngorm application, and each had a "children" property which was an ArrayCollection, and was used for filtering. When profiling, I found that these were one of my biggest memory eaters, so I changed my application to instead store the "parentId" as an int and use this for filtering. The memory used was cut drastically. Something like this:

旧方法:

public class Owner1
{
    public var id:int;
    public var label:String;
    public var children:ArrayCollection; // Stores any number of Owner2 Objects
}

public class Owner2
{
    public var id:int;
    public var label:String;
    public var children:ArrayCollection; // Stores any number of Owner3 Objects
}

public class Owner3
{
    public var id:int;
    public var label:String;
}

新方式:

public class Owner1
{
    public var id:int;
    public var label:String;
}

public class Owner2
{
    public var id:int;
    public var label:String;
    public var parentId:int; // Refers to id of Owner1 Object
}

public class Owner3
{
    public var id:int;
    public var label:String;
    public var parentId:int; // Refers to id of Owner2 Object
}

我还建议删除不再需要的事件侦听器.

I would also suggest removing event listeners when they are no longer needed.

这篇关于调试 FLEX/AS3 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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