jump to navigation

Flex memory leaks and watching property chains September 7, 2011

Posted by maxmil in : Uncategorized , trackback

As a general rule it’s a good idea to always unset any change watchers created via BindingUtils.bindProperty or Changewatcher.watch.

However in display objects this often requires a whole lot of boilerplate code listening for when your component is removed from the stage and even more if you consider that it might be re added at a later date.

Fortunately if you create a change watcher within your display object the scope of that change watcher is limited to the scope of the display object and so it doesn’t prevent the garbage collector from removing the object and watcher when the object is removed from the stage and you can avoid the boilerplate.

However whilst profiling my app today i have discovered that if your change watcher is listening to a property chain rather than a single property then this is not the case.

In this case multiple ChangeWatchers are created that reference each other and this, for some reason unknown to me, prevents the GC from collecting the ChangeWatchers and hence your display object.

Unfortunately in this case the boilerplate seems necessary :(

Love to hear if anyone could explain what is happening here…


no comments yet - be the first?