2
Vote

[Version 2: Commit 94905] LayoutAnchorable Memory Leak (LayoutRoot)

description

If you progmatically add a LayoutAnchorable to a LayoutAnchorablePane then close the LayoutAnchorable, the anchorable sticks around in the LayoutRoot. If you do this repeatedly, many objects build up rapidly.
 
Step 1) Add an anchorable to your pane:
LayoutDocumentPane pane = layoutRoot.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(p => p.Name == "myAnchorablePane");
pane.Children.Add(new LayoutAnchorable());
 
Step 2) Close the window that showed up in the UI.
 
Step 3) Repeat several times.
 
Step 4) Check the ChildrenCount of your LayoutRoot. It is higher than expected. Evaluate the Children of the LayoutRoot. There are a bunch of LayoutAnchorables that you never put there yourself.

comments

adospace wrote Sep 3, 2012 at 8:02 AM

I suppose you only "Hide" the anchorable instead of closing it. By default a LayoutAnchorable is intended to be used as an host for a tool (add-in or so on). When you click the x button or the floating window that host it, AD simply hides it (you'll find the anchorable inside the LayoutRoot.Hidden collection).
In this way the when the user wants to show it again, AD simply reshow the anchorable where it was.
Also the content of the anchorable is not disposed, so when it's shown again it should appear in the same state it has been left.

Ado