diff --git a/source/Components/AvalonDock/DockingManager.cs b/source/Components/AvalonDock/DockingManager.cs index e8bd207b..f71d2cb9 100644 --- a/source/Components/AvalonDock/DockingManager.cs +++ b/source/Components/AvalonDock/DockingManager.cs @@ -27,17 +27,17 @@ This program is provided to you under the terms of the Microsoft Public namespace AvalonDock { - /// - /// - /// - /// The is the custom control at the root of the visual tree. - /// This control is the core control of AvalonDock. - /// It contains core dependency properties, events, and methods to customize and - /// manage many aspects of the docking framework. - /// - /// - /// - [ContentProperty(nameof(Layout))] + /// + /// + /// + /// The is the custom control at the root of the visual tree. + /// This control is the core control of AvalonDock. + /// It contains core dependency properties, events, and methods to customize and + /// manage many aspects of the docking framework. + /// + /// + /// + [ContentProperty(nameof(Layout))] [TemplatePart(Name = "PART_AutoHideArea")] public class DockingManager : Control, IOverlayWindowHost//, ILogicalChildrenContainer { @@ -1731,6 +1731,9 @@ internal void ExecuteCloseCommand(LayoutDocument document) RemoveLogicalChild(uIElement); DocumentClosed?.Invoke(this, new DocumentClosedEventArgs(document)); + //get rid of the closed document content + document.Content = null; + int indexOfDocumentToSelect = indexOfDocumentToRemove - 1; if (indexOfDocumentToSelect < 0) @@ -2198,9 +2201,9 @@ private TLayoutType[] GetItemsToRemoveAfterReset(IEnumerable source var itemsThatRemain = new HashSet(source.Cast(), ReferenceEqualityComparer.Default); //Find the removed items that are not in the remaining collection return Layout.Descendents() - .OfType() - .Where(x => !itemsThatRemain.Contains(x.Content)) - .ToArray(); + .OfType() + .Where(x => !itemsThatRemain.Contains(x.Content)) + .ToArray(); } private void DetachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource) diff --git a/source/Components/AvalonDock/Layout/LayoutContent.cs b/source/Components/AvalonDock/Layout/LayoutContent.cs index f78f04eb..753cd56a 100644 --- a/source/Components/AvalonDock/Layout/LayoutContent.cs +++ b/source/Components/AvalonDock/Layout/LayoutContent.cs @@ -749,8 +749,7 @@ internal void CloseInternal() } parentAsContainer.RemoveChild(this); - root?.CollectGarbage(); - this.Content = null; + root?.CollectGarbage(); OnClosed(); }