From b3c0035b0b8b092ea399b25caa7db000149135cc Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Mon, 18 May 2020 14:01:38 +0200 Subject: [PATCH] Add failing leak test for Path control. --- tests/Avalonia.LeakTests/ControlTests.cs | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/Avalonia.LeakTests/ControlTests.cs b/tests/Avalonia.LeakTests/ControlTests.cs index 0afb2465ee..9bb9fd7145 100644 --- a/tests/Avalonia.LeakTests/ControlTests.cs +++ b/tests/Avalonia.LeakTests/ControlTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.Remoting.Contexts; using Avalonia.Controls; +using Avalonia.Controls.Shapes; using Avalonia.Controls.Templates; using Avalonia.Diagnostics; using Avalonia.Input; @@ -492,6 +493,45 @@ namespace Avalonia.LeakTests } } + [Fact] + public void Path_Is_Freed() + { + using (Start()) + { + var geometry = new EllipseGeometry { Rect = new Rect(0, 0, 10, 10) }; + + Func run = () => + { + var window = new Window + { + Content = new Path + { + Data = geometry + } + }; + + window.Show(); + + window.LayoutManager.ExecuteInitialLayoutPass(window); + Assert.IsType(window.Presenter.Child); + + 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)); + + // We are keeping geometry alive to simulate a resource that outlives the control. + GC.KeepAlive(geometry); + } + } + private IDisposable Start() { return UnitTestApplication.Start(TestServices.StyledWindow.With(