diff options
author | adrianknight89 <adrianknight89@outlook.com> | 2017-01-26 08:24:31 -0600 |
---|---|---|
committer | Kangho Hur <kangho.hur@samsung.com> | 2017-03-24 13:15:52 +0900 |
commit | 4ad3748724c4c36e99fa55e8dc8c2626aa27625b (patch) | |
tree | 070725853971caf8e7465392321d266f22883ca0 /Xamarin.Forms.Controls.Issues | |
parent | 1bec0cd791b2a7288fcae5232b2fad7371fbcf9d (diff) | |
download | xamarin-forms-4ad3748724c4c36e99fa55e8dc8c2626aa27625b.tar.gz xamarin-forms-4ad3748724c4c36e99fa55e8dc8c2626aa27625b.tar.bz2 xamarin-forms-4ad3748724c4c36e99fa55e8dc8c2626aa27625b.zip |
[iOS/Critical] Fix ListView memory leaks (#524)
* fix memory leaks
added sample code
changed page name
Changed page title
add screen instructions
fix copy paste error
change subview dispose logic
Fix context action memory leak
add sample code
change custom page names
Revert "change custom page names"
This reverts commit 7aaab2625d9526080ca5c51c02e909f09ee3f610.
changed class names
changes
UI test for 32206
update ui test
fix whitespace
UITests done
* run UI tests on iOS only
* fix code style
* dispose prototype
* fix child renderer issue
* add null check
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
3 files changed, 280 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32206.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32206.cs new file mode 100644 index 00000000..428538f6 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32206.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using System.Threading; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 32206, "ContextActions cause memory leak: Page is never destroyed", PlatformAffected.iOS)] + public class Bugzilla32206 : TestNavigationPage + { + protected override void Init() + { + PushAsync(new LandingPage32206()); + } + +#if UITEST && __IOS__ + [Test] + public void Bugzilla32206Test() + { + for (var n = 0; n < 10; n++) + { + RunningApp.WaitForElement(q => q.Marked("Push")); + RunningApp.Tap(q => q.Marked("Push")); + + RunningApp.WaitForElement(q => q.Marked("ListView")); + RunningApp.Back(); + } + + // At this point, the counter can be any value, but it's most likely not zero. + // Invoking GC once is enough to clean up all garbage data and set counter to zero + RunningApp.WaitForElement(q => q.Marked("GC")); + RunningApp.Tap(q => q.Marked("GC")); + + RunningApp.WaitForElement(q => q.Marked("Counter: 0")); + } +#endif + } + + [Preserve(AllMembers = true)] + public class LandingPage32206 : ContentPage + { + public static int Counter; + public Label Label; + + public LandingPage32206() + { + Label = new Label + { + Text = "Counter: " + Counter, + HorizontalTextAlignment = TextAlignment.Center, + VerticalTextAlignment = TextAlignment.Center + }; + + Content = new StackLayout + { + Orientation = StackOrientation.Vertical, + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + Spacing = 15, + Children = + { + new Label + { + Text = "Click Push to show a ListView. When you hit the Back button, Counter will show the number of pages that have not been finalized yet." + + " If you click GC, the counter should be 0." + }, + Label, + new Button + { + Text = "GC", + AutomationId = "GC", + Command = new Command(o => + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + Label.Text = "Counter: " + Counter; + }) + }, + new Button + { + Text = "Push", + AutomationId = "Push", + Command = new Command(async o => + { + await Navigation.PushAsync(new ContentPage32206()); + }) + } + } + }; + } + + protected override void OnAppearing() + { + base.OnAppearing(); + + if (Label != null) + Label.Text = "Counter: " + Counter; + } + } + + [Preserve(AllMembers = true)] + public class ContentPage32206 : ContentPage + { + public ContentPage32206() + { + Interlocked.Increment(ref LandingPage32206.Counter); + System.Diagnostics.Debug.WriteLine("Page: " + LandingPage32206.Counter); + + Content = new ListView + { + ItemsSource = new List<string> { "Apple", "Banana", "Cherry" }, + ItemTemplate = new DataTemplate(typeof(ViewCell32206)), + AutomationId = "ListView" + }; + } + + ~ContentPage32206() + { + Interlocked.Decrement(ref LandingPage32206.Counter); + System.Diagnostics.Debug.WriteLine("Page: " + LandingPage32206.Counter); + } + } + + [Preserve(AllMembers = true)] + public class ViewCell32206 : ViewCell + { + public ViewCell32206() + { + View = new Label(); + View.SetBinding(Label.TextProperty, "."); + ContextActions.Add(new MenuItem { Text = "Delete" }); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla43941.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla43941.cs new file mode 100644 index 00000000..b69e968a --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla43941.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using System.Threading; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 43941, "Memory leak with ListView's RecycleElement on iOS", PlatformAffected.iOS)] + public class Bugzilla43941 : TestNavigationPage + { + protected override void Init() + { + PushAsync(new LandingPage43941()); + } + +#if UITEST && __IOS__ + [Test] + public void Bugzilla43941Test() + { + for (var n = 0; n < 10; n++) + { + RunningApp.WaitForElement(q => q.Marked("Push")); + RunningApp.Tap(q => q.Marked("Push")); + + RunningApp.WaitForElement(q => q.Marked("ListView")); + RunningApp.Back(); + } + + // At this point, the counter can be any value, but it's most likely not zero. + // Invoking GC once is enough to clean up all garbage data and set counter to zero + RunningApp.WaitForElement(q => q.Marked("GC")); + RunningApp.Tap(q => q.Marked("GC")); + + RunningApp.WaitForElement(q => q.Marked("Counter: 0")); + } +#endif + } + + [Preserve(AllMembers = true)] + public class ContentPage43941 : ContentPage + { + public ContentPage43941() + { + Interlocked.Increment(ref LandingPage43941.Counter); + System.Diagnostics.Debug.WriteLine("Page: " + LandingPage43941.Counter); + + var list = new List<int>(); + for (var i = 0; i < 30; i++) + list.Add(i); + + Title = "ContentPage43941"; + Content = new ListView + { + HasUnevenRows = true, + ItemsSource = list, + AutomationId = "ListView" + }; + } + + ~ContentPage43941() + { + Interlocked.Decrement(ref LandingPage43941.Counter); + System.Diagnostics.Debug.WriteLine("Page: " + LandingPage43941.Counter); + } + } + + [Preserve(AllMembers = true)] + public class LandingPage43941 : ContentPage + { + public static int Counter; + public Label Label; + + public LandingPage43941() + { + Label = new Label + { + Text = "Counter: " + Counter, + HorizontalTextAlignment = TextAlignment.Center, + VerticalTextAlignment = TextAlignment.Center + }; + + Content = new StackLayout + { + Orientation = StackOrientation.Vertical, + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + Spacing = 15, + Children = + { + new Label + { + Text = "Click Push to show a ListView. When you hit the Back button, Counter will show the number of pages that have not been finalized yet." + + " If you click GC, the counter should be 0." + }, + Label, + new Button + { + Text = "GC", + AutomationId = "GC", + Command = new Command(o => + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + Label.Text = "Counter: " + Counter; + }) + }, + new Button + { + Text = "Push", + AutomationId = "Push", + Command = new Command(async o => + { + await Navigation.PushAsync(new ContentPage43941()); + }) + } + } + }; + } + + protected override void OnAppearing() + { + base.OnAppearing(); + + if (Label != null) + Label.Text = "Counter: " + Counter; + } + } +}
\ 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 fab19248..2d6ddb58 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 @@ -51,6 +51,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla31964.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla32033.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla32034.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Bugzilla32206.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla32776.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla32842.xaml.cs"> <DependentUpon>Bugzilla32842.xaml</DependentUpon> @@ -139,6 +140,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43313.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43469.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43516.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43941.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43663.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43735.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla44453.cs" /> |