From 768c5c0f5e0c711c8bfd2784bc0270f353e3fc5e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 3 Mar 2016 09:48:55 +0100 Subject: [PATCH] Added new failing leak test. --- tests/Perspex.LeakTests/ControlTests.cs | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/Perspex.LeakTests/ControlTests.cs b/tests/Perspex.LeakTests/ControlTests.cs index 1577628c94..6016662f8e 100644 --- a/tests/Perspex.LeakTests/ControlTests.cs +++ b/tests/Perspex.LeakTests/ControlTests.cs @@ -257,6 +257,55 @@ namespace Perspex.LeakTests } } + [Fact] + public void Class_Listener_Is_Freed() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + Func run = () => + { + var window = new Window + { + Styles = new Styles + { + new Style(x => x.OfType().Class("foo")) + { + Setters = new[] + { + new Setter(Border.BorderThicknessProperty, 1), + } + } + }, + Content = new Border + { + Classes = new Classes("foo"), + } + }; + + // Do a layout and make sure that TreeViewItems get realized. + LayoutManager.Instance.ExecuteInitialLayoutPass(window); + Assert.Equal(1, ((Border)window.Content).BorderThickness); + + // Clear the content and ensure the TreeView is removed. + window.Content = null; + LayoutManager.Instance.ExecuteLayoutPass(); + Assert.Null(window.Presenter.Child); + + return window; + }; + + var result = run(); + + var type = Type.GetType( + "System.Reactive.Linq.ObservableImpl.FromEventPattern+Impl`2[[System.Collections.Specialized.NotifyCollectionChangedEventHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Specialized.NotifyCollectionChangedEventArgs, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.Reactive.Linq, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + + Assert.NotNull(type); + + dotMemory.Check(memory => + Assert.Equal(0, memory.GetObjects(where => where.Type.Is(type)).ObjectsCount)); + } + } + private class TestTemplatedControl : TemplatedControl { public static readonly StyledProperty IsCanvasVisibleProperty =