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() {