From a2fee1d21e2b11f1a45cdf1d856731fb268942bd Mon Sep 17 00:00:00 2001 From: kicsiede <4233752+kicsiede@users.noreply.github.com> Date: Wed, 7 Feb 2018 01:51:46 +0100 Subject: [PATCH] Update NavigationUnitTest.cs --- .../NavigationUnitTest.cs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs b/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs index fb68d14e7..304089487 100644 --- a/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs +++ b/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs @@ -559,6 +559,26 @@ namespace Xamarin.Forms.Core.UnitTests Assert.That (popped, Is.Null); Assert.That (navPage.CurrentPage, Is.SameAs (root)); } + + [Test] + [Property("Bugzilla", 31171)] + public async Task ReleasesPoppedPage() + { + var root = new ContentPage { Title = "Root" }; + var navPage = new NavigationPage(root); + + var isFinalized = false; + + await navPage.PushAsync(new PageWithFinalizer(() => isFinalized = true)); + await navPage.PopAsync(); + + await Task.Delay(100); + + GC.Collect(); + GC.WaitForPendingFinalizers(); + + Assert.IsTrue(isFinalized); + } } internal class BackButtonPage : ContentPage @@ -574,4 +594,18 @@ namespace Xamarin.Forms.Core.UnitTests return Handle; } } -} \ No newline at end of file + + internal class PageWithFinalizer : Page + { + Action OnFinalize; + public PageWithFinalizer(Action onFinalize) + { + OnFinalize = onFinalize; + } + + ~PageWithFinalizer() + { + OnFinalize(); + } + } +}