forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bugzilla31145.cs
68 lines (56 loc) · 1.62 KB
/
Bugzilla31145.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
using System;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Controls
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 31145, "Picker cause memory leak holding entire Page in memory after it popped (WP8 SL only)", PlatformAffected.WinPhone)]
public class Bugzilla31145 : TestContentPage
{
WeakReference _page2Tracker;
Label _resultLabel;
protected override void Init()
{
var instructions = new Label () { Text = "The counter below should say 'Page2 IsAlive = false' after a short period of time. If the counter does not say that within 5 seconds, this test has failed." };
_resultLabel = new Label ();
Content = new StackLayout { Children = { instructions, _resultLabel } };
}
protected override async void OnAppearing()
{
base.OnAppearing();
if (_page2Tracker == null)
{
var page2 = new Bugzilla31145Page2();
_page2Tracker = new WeakReference(page2, false);
await Task.Yield();
await Navigation.PushModalAsync(page2);
StartTrackPage2();
}
}
async void StartTrackPage2()
{
var n = 0;
while (_page2Tracker.IsAlive)
{
_resultLabel.Text = $"Page2 IsAlive = {_page2Tracker.IsAlive} ({n++})";
await Task.Delay(1000);
GC.Collect();
}
_resultLabel.Text = $"Page2 IsAlive = {_page2Tracker.IsAlive}";
}
}
public class Bugzilla31145Page2 : ContentPage
{
public Bugzilla31145Page2()
{
Content = new Picker();
}
protected override async void OnAppearing()
{
base.OnAppearing();
await Task.Yield();
await Navigation.PopModalAsync();
}
}
}