diff --git a/tests/Perspex.LeakTests/ControlTests.cs b/tests/Perspex.LeakTests/ControlTests.cs index 557f04f794..a44532dc5c 100644 --- a/tests/Perspex.LeakTests/ControlTests.cs +++ b/tests/Perspex.LeakTests/ControlTests.cs @@ -49,6 +49,38 @@ namespace Perspex.LeakTests Assert.Equal(0, memory.GetObjects(where => where.Type.Is()).ObjectsCount)); } + [Fact] + public void Named_Canvas_Is_Freed() + { + Func run = () => + { + var window = new Window + { + Content = new Canvas + { + Name = "foo" + } + }; + + // Do a layout and make sure that Canvas gets added to visual tree. + window.LayoutManager.ExecuteLayoutPass(); + Assert.IsType(window.Find("foo")); + Assert.IsType(window.Presenter.Child); + + // Clear the content and ensure the Canvas is removed. + window.Content = null; + window.LayoutManager.ExecuteLayoutPass(); + Assert.Null(window.Presenter.Child); + + return window; + }; + + var result = run(); + + dotMemory.Check(memory => + Assert.Equal(0, memory.GetObjects(where => where.Type.Is()).ObjectsCount)); + } + [Fact] public void TreeView_Is_Freed() {