-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Bugzilla45722Xaml0.xaml.cs
135 lines (109 loc) · 2.95 KB
/
Bugzilla45722Xaml0.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Xaml;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[NUnit.Framework.Category(UITestCategories.ListView)]
[NUnit.Framework.Category(UITestCategories.UwpIgnore)]
[NUnit.Framework.Category(Core.UITests.UITestCategories.Bugzilla)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 45722, "Memory leak in Xamarin Forms ListView",
PlatformAffected.UWP, issueTestNumber: 1)]
public partial class Bugzilla45722Xaml0 : TestContentPage
{
const int ItemCount = 10;
const string Success = "Success";
const string Running = "Running...";
const string Update = "Refresh";
const string Collect = "GC";
public Bugzilla45722Xaml0()
{
#if APP
InitializeComponent ();
Model = new ObservableCollection<_45722Group>();
RefreshModel();
IsGroupingEnabled = true;
BindingContext = this;
RefreshButton.Clicked += (sender, args) => { RefreshModel(); };
GCButton.Clicked += (sender, args) =>
{
GarbageCollectionHelper.Collect();
};
MessagingCenter.Subscribe<_45722Label>(this, _45722Label.CountMessage, sender =>
{
Device.BeginInvokeOnMainThread(() =>
{
CurrentCount.Text = _45722Label.Count.ToString();
// GroupHeader label + (3 items per group * 2 labels per item) = 7
Result.Text = (_45722Label.Count - (ItemCount * 7)) <= 0 ? Success : Running;
});
});
#endif
}
protected override void Init()
{
}
protected override void OnDisappearing()
{
MessagingCenter.Unsubscribe<_45722Label>(this, _45722Label.CountMessage);
base.OnDisappearing();
}
public ObservableCollection<_45722Group> Model { get; }
public bool IsGroupingEnabled { get; }
void RefreshModel()
{
Model.Clear();
for (int n = 0; n < ItemCount; n++)
{
var group = new _45722Group($"{n}", new[]
{
new _45722Item($"{n}-1", $"{n}-1 description"),
new _45722Item($"{n}-2", $"{n}-2 description"),
new _45722Item($"{n}-3", $"{n}-3 description")
});
Model.Add(group);
}
}
#if UITEST && __WINDOWS__
[Test]
public void LabelsInListViewTemplatesShouldBeCollected()
{
RunningApp.WaitForElement(Update);
for(int n = 0; n < 10; n++)
{
RunningApp.Tap(Update);
}
RunningApp.Tap(Collect);
RunningApp.WaitForElement(Success);
}
#endif
}
public class _45722Group : ObservableCollection<_45722Item>
{
public _45722Group(string key, IEnumerable<_45722Item> items) : base(items)
{
Key = key;
}
public string Key { get; set; }
}
public class _45722Item
{
public _45722Item(string listName, string listDescription)
{
ListName = listName;
ListDescription = listDescription;
}
public string ListName { get; set; }
public string ListDescription { get; set; }
}
}