FLEX / AS3 Memory Leak Debugging

I have a fairly large Flex and Papervision3D application that constantly creates and destroys objects. It also downloads and uploads SWF resource files. While it is running, SWF slowly consumes memory up to about 2 GB when it spins the player. Obviously, I'm pretty sure that I'm sending a link to examples that I no longer want with the expectation that the GC will do its job. But I have damn time to figure out where the problem is.

I tried using the profiler and its parameters to capture snapshots of memory, etc., but my problem remains evasive. I think there are known issues with using a debug flash player? But I do not get the joy of using the release version.

How are you going to track memory leak problems with FLEX / AS3? What are some strategies, tricks or tools that you used to look for consumption.

+6
debugging flex memory-leaks actionscript-3 papervision3d
source share
4 answers

I came across something explaining how to use Flex Profiler in Flex Builder, and this was a HUGE help for troubleshooting memory leaks. I would definitely suggest a try. It is very easy to use. Some things I found while profiling my applications:

Avoid using collections (at least LARGE collections) as properties of Value objects. I had several types of value object classes in a Cairngorm application, and each of them had a "children" property that was an ArrayCollection and was used for filtering. When profiling, I found that they were one of my biggest memory absorbers, so I changed my application, instead saved β€œparentId” as an int and used it for filtering. Used memory has been drastically reduced. Something like that:

Old way:

 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; } 

New way:

 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 also suggest removing event listeners when they are no longer needed.

+3
source share

I usually use the cleanup method in every class I make (since AS has no destructors). The main problem that I noticed with the GC is event listeners. In addition to what has been said, also try to avoid the anonymous functions of the listener (since you cannot explicitly remove them). Here are some links you might find useful:

+4
source share

due to such problems, I developed an open source library that helps control all the events that you are executing at any given time. it is very easy to implement, and I re-earned projects in 10-15 minutes to convert them into the used EventController.

basically for your scenario, I would run through all the events and replace them: obj.addEventListener (...);

: EC.add (object, ...);

the rest is the same thing to do this is to register an event and make it crazy, it is easy to see all your events at any time using EC.log ();

all the details and documentation are on my site, I would like to know if this will help you, and if you start working with it. if you have good or bad feedback, feel free to post it and I would look at it!

website: http://fla.as/ec/

+3
source share

If your memory leak grows exponentially, this probably means that the GC is not doing its job. Take a look at your code and see where you can reduce the number of references to objects (by setting them to null ). Make event handlers weak. And re-profile.

+2
source share

All Articles