This project is read-only.

[Version 2.0] Possible memory leak

Aug 7, 2012 at 2:57 PM

We are using Avalon Dock (SVN from 6 August 2012 Commit:94577 - Build:201324), and we are encountering some memory leak issues, which we are trying to determine the cause of.

What I fail to understand is when LayoutDocumentPaneControl.InternalRemoveLogicalChild should be called. It seems that whenever we add a new tab to the dock, InternalAddLogicalChild gets called, but InternalRemove(...) is only called when we undock the tab and dock it again - NOT when we close the tab using the X button on the header. In the cases of docking and undocking, it will be immediately following by another called to InternalAdd(...)

This means - in our case - that _logicalChildren grows whenever we open a new tab. It maintains a reference to our views, meaning that they will never be garbage collected.

Can anyone point me in the right direction to determine if this is the right behaviour, or if we have introduced an error somewhere.

When are elements supposed to leave the _logicalChildren collection on LayoutDocumentPaneControl?

Aug 8, 2012 at 9:46 AM

I use a LayoutDocumentPane in my app, and I subscribe to the DocumentClosing event on its DockingManager.
In the handler, I dispose whatever needs disposing in the view.

Now I load UserControls that weight from 30 to 50Mo each in memory so it's pretty obvious when they're GC'd and when they aren't,
and I can assure you they are.

Did you have that issue with the old version or is this a new project?

Aug 8, 2012 at 12:02 PM

We didn't (as far as I am aware) have any leak problems in 1.3.


My problem is very specific to the _logicalChildren collection. Since it is an internal collection, we can't modify it - yet it still retains the references. I've been looking through the source code, but I've been unable to determine what is causing this collection to never be emptied.


Our controls themselves don't hold anything that should be disposed as such - the problem is that there is a hard reference to our views from AvalonDock.

Aug 8, 2012 at 7:04 PM

It appears to be a serious problem, I'll investigate the issue and I'll back to you soon, Ado

Aug 9, 2012 at 8:06 AM

Sounds good, thanks! Let me know if you can see the issue, or I can try to create a sample for you.

Aug 9, 2012 at 8:11 PM


I have a similar problem, described in a previous discussion "[Version 2.0] DocumentsSource bound to ObservableCollection<ContentControl>". From my investigation after reading this thread I think that the control is being removed from the _logicalChildren collection but is still being referenced by DockingManager, somewhere. Please see other discussion for more detail.



Aug 10, 2012 at 7:58 AM

In my case, the control remains in _logicalChildren. We are also binding to an ObservableCollection<T>. I have a creeping suspicion that there is a problem when binding to UIElements.


We bind DocumentsSource on DockingManager to an ObservableCollection<ViewBase>. where ViewBase inherits from UserControl.

Aug 10, 2012 at 6:18 PM

Hi, I've fixed the issue in latest build, please download it and see if it works in your scenario, Thanks for the great issue report, Ado

Aug 10, 2012 at 9:32 PM

Initial test suggests the problem I had is fixed, thanks.


Aug 13, 2012 at 10:05 AM

Awesome, I will try it at once.

Aug 13, 2012 at 10:32 AM

That fixed the problem for us. Thank you very much. Support for this free control is better than most of the paid third party components we use :)