调试FLEX / AS3内存泄漏内存、FLEX

2023-09-09 21:42:39 作者:给不了你嫁衣绝不碰你内衣

我有一个pretty的大的Flex和放大器; Papervision3D的应用程序,创建并不断破坏的对象。它还加载和卸载SWF资源文件了。虽然它的运行的SWF慢慢消耗内存直到约2GB,当它croaks玩家。很显然,我是pretty的肯定,我放手的参考实例,我不再想与预期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探查在Flex Builder,这是一个巨大的帮助,我在调试内存泄漏。我肯定会建议尝试一下。这是非常容易使用。有些事情,我发现我的分析应用程序时:

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:

避免使用集合(至少大集合)作为价值对象的属性。我在我的凯恩戈姆的应用程序有几种类型的值对象类,并且每过一个孩子属性,它是一个的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.