From f20e26ea38282ab9713d6bb47be7cbb9c09819ab Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 30 Nov 2015 22:47:23 +0100 Subject: [PATCH] TextBox ScrollViewer doesn't get released When TextBox.Template is cleared. This is showing up as a leak when a TextBox is contained in a TabControl and tabs get changed. --- tests/Perspex.LeakTests/ControlTests.cs | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Perspex.LeakTests/ControlTests.cs b/tests/Perspex.LeakTests/ControlTests.cs index abc4280357..c770fb1c16 100644 --- a/tests/Perspex.LeakTests/ControlTests.cs +++ b/tests/Perspex.LeakTests/ControlTests.cs @@ -188,6 +188,36 @@ namespace Perspex.LeakTests Assert.Equal(0, memory.GetObjects(where => where.Type.Is()).ObjectsCount)); } + [Fact] + public void TextBox_ScrollViewer_Is_Freed_When_Template_Cleared() + { + Func run = () => + { + var window = new Window + { + Content = new TextBox() + }; + + // Do a layout and make sure that TextBox gets added to visual tree and its + // template applied. + window.LayoutManager.ExecuteLayoutPass(); + Assert.IsType(window.Presenter.Child); + Assert.NotEqual(0, window.Presenter.Child.GetVisualChildren().Count()); + + // Clear the template and ensure the TextBox template gets removed + ((TextBox)window.Content).Template = null; + window.LayoutManager.ExecuteLayoutPass(); + Assert.Equal(0, window.Presenter.Child.GetVisualChildren().Count()); + + return window; + }; + + var result = run(); + + dotMemory.Check(memory => + Assert.Equal(0, memory.GetObjects(where => where.Type.Is()).ObjectsCount)); + } + [Fact] public void TreeView_Is_Freed() {