jump to navigation

Flex Memory Leak in mx.core.Container class August 29, 2007

Posted by khurram in Adobe, Flex, memory leak, mx.core.Container.

We ran into this issue while debugging memory issues in our flex application. This issue has been fixed in the latest beta version of the Flash Player Here is the issue for your reference as it might help you debug memory issues in your application, also download and run the example source to replicate it.

As I was debugging some of the memory issues we are having, I noticed that the objects of types container do not get garbage collected if they have one or more children specified as MXML tags (or alternatively added through component descriptors). I looked at the mx.core.Container class and noticed that it keeps an array called _createdComponents of all the components that were created through their descriptors. It populates that array in the createComponentsFromDescriptors method. The problem is that it never gets rid of the components in the array when they are removed by calling any of the remove methods such as removeAllchildren, removeChildAt etc. That array thus keeps a strong reference to children that had already been deleted and should have been garbage collected. This also gives rise to a circular reference case where the parent and the child both don’t get GC’d.

I have created a small program that might be helpful in reproducing this bug.

  1. After you load the files into a project, run the swf
  2. Click on “Create AS based child”
  3. Click on “Trace Reference”, it will show you the created children
  4. Click on “Remove All” and then “Force GC”
  5. Click on trace reference, you will see no references
  6. Click on “Create Descriptor based child”
  7. Click on “Trace Reference”, it will show you the created children
  8. Click on “Remove All” and then “Force GC”
  9. Click on “Trace Reference”, you will notice that the reference still hangs around even after it has been deleted and GC has run

There is another memory leak that occurs when you specify verticalGap or horizontalGap attributes on any container. This issue has also been resolved in the Flash Player version specified above.



1. New Flex Blog to add to your Favorite Feed Reader « Tom’s Blog - August 31, 2007

[…] There you will find posts on hard hitting technical Flex issues such as Memory Leaks in Classes to lighter UI topics like Fun with Icons. The things we’re doing here are pretty amazing and […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: