diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1895.cs | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1895.cs')
-rw-r--r-- | Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1895.cs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1895.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1895.cs new file mode 100644 index 00000000..1e65ecf9 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1895.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xamarin.Forms.CustomAttributes; + +namespace Xamarin.Forms.Controls.TestCasesPages +{ + [Preserve (AllMembers=true)] + [Issue (IssueTracker.Github, 1895, "ListView with static BindingContext somehow leaks memory", PlatformAffected.iOS | PlatformAffected.Android)] + public class Issue1895 + : ContentPage + { + public Issue1895() + { + var button = new Button { Text = "Push weak page" }; + button.Clicked += async (sender, args) => await Navigation.PushAsync (CreateWeakReferencedPage()); + Content = button; + } + + static List<WeakReference> s_pageRefs = new List<WeakReference>(); + static FakeProvider s_fakeProvider = new FakeProvider(); + + static Page CreateWeakReferencedPage() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + + var result = CreatePage(); + s_pageRefs.Add(new WeakReference(result)); + + return result; + } + + class WeakReferencedPage : ContentPage + { + + } + + static Page CreatePage() + { + var page = new WeakReferencedPage(); + var contents = new StackLayout(); + + contents.Children.Add (new Button { + Text = "Next Page", + Command = new Command(() => page.Navigation.PushAsync(CreateWeakReferencedPage())) + }); + + contents.Children.Add (new Label { + Text = string.Format ("References alive at time of creation: {0}", s_pageRefs.Count(p => p.IsAlive)), + HorizontalOptions = LayoutOptions.CenterAndExpand + }); + + var listView = new ListView { BindingContext = s_fakeProvider }; + listView.SetBinding (ListView.ItemsSourceProperty, "Items"); + contents.Children.Add (listView); + + page.Content = contents; + return page; + } + + class FakeProvider + { + public ObservableCollection<string> Items { get; private set; } + + public FakeProvider() + { + Items = new ObservableCollection<string>(); + Items.Add("Item 1"); + Items.Add("Item 2"); + Items.Add("Item 3"); + Items.Add("Item 4"); + } + } + } +}
\ No newline at end of file |