[Android] add another gc.collect for Android to ensure all is collected (#5847)
* add another gc.collect for Android * move all gc collects to a helper
This commit is contained in:
Родитель
32da34df0e
Коммит
cbc9c44297
|
@ -43,7 +43,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
{
|
||||
_resultLabel.Text = $"Page2 IsAlive = {_page2Tracker.IsAlive} ({n++})";
|
||||
await Task.Delay(1000);
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
}
|
||||
|
||||
_resultLabel.Text = $"Page2 IsAlive = {_page2Tracker.IsAlive}";
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
((Label)((StackLayout)Content).Children [0]).Text =
|
||||
string.Format ("Page1. But Page2 IsAlive = {0}", _page2Tracker.IsAlive);
|
||||
await Task.Delay (1000);
|
||||
GC.Collect ();
|
||||
GarbageCollectionHelper.Collect();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,9 +78,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
AutomationId = "GC",
|
||||
Command = new Command(o =>
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
Label.Text = "Counter: " + Counter;
|
||||
})
|
||||
},
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
while (_page2Tracker.IsAlive && _tabTracker.IsAlive && watch.ElapsedMilliseconds < Timeout)
|
||||
{
|
||||
await Task.Delay (1000);
|
||||
GC.Collect ();
|
||||
GarbageCollectionHelper.Collect();
|
||||
}
|
||||
|
||||
watch.Stop();
|
||||
|
|
|
@ -63,8 +63,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
async void Button_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
Debug.WriteLine(">>>>>>>> Invoking Garbage Collector");
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
|
||||
await Navigation.PushAsync(new BugPage());
|
||||
}
|
||||
|
|
|
@ -93,8 +93,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
void GCbutton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(">>>>>>>> Running Garbage Collection");
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
System.Diagnostics.Debug.WriteLine($">>>>>>>> GC.GetTotalMemory = {GC.GetTotalMemory(true):n0}");
|
||||
}
|
||||
|
||||
|
|
|
@ -131,9 +131,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
GC.Collect();
|
||||
GC.Collect();
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,9 +53,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
var collectButton = new Button { Text = "Collect" };
|
||||
collectButton.Clicked += (sender, args) =>
|
||||
{
|
||||
GC.Collect();
|
||||
GC.Collect();
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
};
|
||||
|
||||
var startPage = new ContentPage
|
||||
|
|
|
@ -145,9 +145,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
GC.Collect();
|
||||
GC.Collect();
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,8 +106,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
AutomationId = "GC",
|
||||
Command = new Command(o =>
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
Label.Text = "Counter: " + Counter;
|
||||
})
|
||||
},
|
||||
|
|
|
@ -44,9 +44,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
{
|
||||
public Page2()
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
|
||||
Title = "Page2";
|
||||
System.Diagnostics.Debug.WriteLine("Constructor");
|
||||
|
|
|
@ -26,8 +26,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
var gcButton = new Button { Text = "GC", AutomationId = "GC" };
|
||||
gcButton.Clicked += (sender, args) =>
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
|
||||
if (_44166MDP.Counter > 0)
|
||||
{
|
||||
|
|
|
@ -98,8 +98,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
var collect = new Button() { Text = Collect };
|
||||
collect.Clicked += (sender, args) =>
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
};
|
||||
|
||||
Title = "Bugzilla 45722";
|
||||
|
|
|
@ -45,8 +45,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
|
||||
GCButton.Clicked += (sender, args) =>
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
};
|
||||
|
||||
MessagingCenter.Subscribe<_45722Label>(this, _45722Label.CountMessage, sender =>
|
||||
|
|
|
@ -51,8 +51,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
};
|
||||
|
||||
doGC.Clicked += (sender, e) => {
|
||||
GC.Collect ();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
instanceCount.Text = $"Instances: {_45926SecondPage.InstanceCounter.ToString()}";
|
||||
messageCount.Text = $"Messages: {_45926SecondPage.MessageCounter.ToString()}";
|
||||
};
|
||||
|
|
|
@ -36,8 +36,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
|
||||
async void Button_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
|
||||
await Navigation.PushAsync(new ChildPage());
|
||||
}
|
||||
|
|
|
@ -52,8 +52,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
|
||||
var collectButton = new Button { Text = "Garbage", Command = new Command(o =>
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
_layout.Children.Add(new Label {Text = "Success"});
|
||||
}) };
|
||||
_layout.Children.Add(collectButton);
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
async void Button_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
await Navigation.PushAsync(new ListPage());
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
public static class GarbageCollectionHelper
|
||||
{
|
||||
public static void Collect()
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -78,9 +78,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
AutomationId = "GC",
|
||||
Command = new Command(o =>
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
Label.Text = "Counter: " + Counter;
|
||||
})
|
||||
},
|
||||
|
|
|
@ -78,9 +78,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
AutomationId = "GC",
|
||||
Command = new Command(o =>
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
Label.Text = "Counter: " + Counter;
|
||||
})
|
||||
},
|
||||
|
|
|
@ -25,14 +25,14 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
|
||||
static Page CreateWeakReferencedPage()
|
||||
{
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
var result = CreatePage();
|
||||
s_pageRefs.Add(new WeakReference(result));
|
||||
|
||||
// Add a second unreferenced page to prove that the problem only exists
|
||||
// when pages are actually navigated to/from
|
||||
s_pageRefs.Add(new WeakReference(CreatePage()));
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,9 +26,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
|
||||
static Page CreateWeakReferencedPage()
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
|
||||
var result = CreatePage();
|
||||
s_pageRefs.Add(new WeakReference(result));
|
||||
|
|
|
@ -50,8 +50,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
Text = "Garbage Collection Things",
|
||||
Command = new Command(() =>
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
AttachedStateEffects.Clear();
|
||||
}),
|
||||
},
|
||||
|
@ -76,16 +75,14 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
// needed otherwise UWP crashes
|
||||
await Task.Delay(100);
|
||||
await Navigation.PopAsync();
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
}
|
||||
|
||||
void OnAllEventsDetached(object sender, EventArgs args)
|
||||
{
|
||||
AttachedStateEffects.Clear();
|
||||
AttachedStateEffects.AllEventsDetached -= OnAllEventsDetached;
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GarbageCollectionHelper.Collect();
|
||||
AllEffectsHaveDetached.Text = "Success";
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
result.Text = "Click 'Push page' again";
|
||||
return;
|
||||
}
|
||||
|
||||
GarbageCollectionHelper.Collect();
|
||||
result.Text = list[list.Count - 2].IsAlive ? "Failed" : "Success";
|
||||
})
|
||||
};
|
||||
|
@ -76,9 +78,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
await Navigation.PushAsync(page);
|
||||
await page.Navigation.PopAsync();
|
||||
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
GarbageCollectionHelper.Collect();
|
||||
|
||||
list.Add(wref);
|
||||
if (list.Count > 1)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<Import_RootNamespace>Xamarin.Forms.Controls.Issues</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Helpers\GarbageCollectionHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue5555.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59172.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue4684.xaml.cs" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче