From 6aa96a43915edaa8fa03ab9bf5abf00fd424f3f1 Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Tue, 27 Sep 2016 04:51:22 -0600 Subject: Clean up listeners and tag on ButtonRenderer during disposal (#360) Clean up OnFocusChangeListener on ViewRenderer during disposal Prevent memory leak of PageContainer/FragmentContainer when animating fragment transitions Call Destroy() on Map during disposal Rebasing --- .../Bugzilla39489.cs | 75 ++++++++++++++++++++++ .../Xamarin.Forms.Controls.Issues.Shared.projitems | 1 + 2 files changed, 76 insertions(+) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39489.cs (limited to 'Xamarin.Forms.Controls.Issues') diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39489.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39489.cs new file mode 100644 index 00000000..266b0fa6 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39489.cs @@ -0,0 +1,75 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using System.Threading; +using System; +using System.Threading.Tasks; +using Xamarin.Forms.Maps; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 39489, "Memory leak when using NavigationPage with Maps", PlatformAffected.Android)] + public class Bugzilla39489 : TestNavigationPage + { + protected override void Init() + { + PushAsync(new Bz39489Content()); + } + + #if UITEST + [Test] + public async void Bugzilla39458Test() + { + // Original bug report (https://bugzilla.xamarin.com/show_bug.cgi?id=39489) had a crash (OOM) after 25-30 + // page loads. Obviously it's going to depend heavily on the device and amount of available memory, but + // if this starts failing before 50 we'll know we've sprung another serious leak + int iterations = 50; + + for (int n = 0; n < iterations; n++) + { + RunningApp.WaitForElement(q => q.Marked("New Page")); + RunningApp.Tap(q => q.Marked("New Page")); + RunningApp.WaitForElement(q => q.Marked("New Page")); + await Task.Delay(1000); + RunningApp.Back(); + } + } + #endif + } + + [Preserve(AllMembers = true)] + public class Bz39489Content : ContentPage + { + public Bz39489Content() + { + var button = new Button { Text = "New Page" }; + + var gcbutton = new Button { Text = "GC" }; + + var map = new Map(); + + button.Clicked += Button_Clicked; + gcbutton.Clicked += GCbutton_Clicked; + + Content = new StackLayout { Children = { button, gcbutton, map } }; + } + + void GCbutton_Clicked(object sender, EventArgs e) + { + System.Diagnostics.Debug.WriteLine(">>>>>>>> Running Garbage Collection"); + GC.Collect(); + GC.WaitForPendingFinalizers(); + System.Diagnostics.Debug.WriteLine($">>>>>>>> GC.GetTotalMemory = {GC.GetTotalMemory(true):n0}"); + } + + void Button_Clicked(object sender, EventArgs e) + { + Navigation.PushAsync(new Bz39489Content()); + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 364b3c44..7a47c10f 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -437,6 +437,7 @@ + -- cgit v1.2.3