{
_resultLabel.Text = $"Page2 IsAlive = {_page2Tracker.IsAlive} ({n++})";
await Task.Delay(1000);
- GC.Collect();
+ GarbageCollectionHelper.Collect();
}
_resultLabel.Text = $"Page2 IsAlive = {_page2Tracker.IsAlive}";
((Label)((StackLayout)Content).Children [0]).Text =
string.Format ("Page1. But Page2 IsAlive = {0}", _page2Tracker.IsAlive);
await Task.Delay (1000);
- GC.Collect ();
+ GarbageCollectionHelper.Collect();
}
}
AutomationId = "GC",
Command = new Command(o =>
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
+ GarbageCollectionHelper.Collect();
Label.Text = "Counter: " + Counter;
})
},
while (_page2Tracker.IsAlive && _tabTracker.IsAlive && watch.ElapsedMilliseconds < Timeout)
{
await Task.Delay (1000);
- GC.Collect ();
+ GarbageCollectionHelper.Collect();
}
watch.Stop();
async void Button_Clicked(object sender, EventArgs e)
{
Debug.WriteLine(">>>>>>>> Invoking Garbage Collector");
- GC.Collect();
- GC.WaitForPendingFinalizers();
+ GarbageCollectionHelper.Collect();
await Navigation.PushAsync(new BugPage());
}
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}");
}
protected override void OnAppearing()
{
base.OnAppearing();
- GC.Collect();
- GC.Collect();
- GC.Collect();
+ GarbageCollectionHelper.Collect();
}
}
}
var collectButton = new Button { Text = "Collect" };
collectButton.Clicked += (sender, args) =>
{
- GC.Collect();
- GC.Collect();
- GC.Collect();
+ GarbageCollectionHelper.Collect();
};
var startPage = new ContentPage
protected override void OnAppearing()
{
base.OnAppearing();
- GC.Collect();
- GC.Collect();
- GC.Collect();
+ GarbageCollectionHelper.Collect();
}
}
}
AutomationId = "GC",
Command = new Command(o =>
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
+ GarbageCollectionHelper.Collect();
Label.Text = "Counter: " + Counter;
})
},
{
public Page2()
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
+ GarbageCollectionHelper.Collect();
Title = "Page2";
System.Diagnostics.Debug.WriteLine("Constructor");
var gcButton = new Button { Text = "GC", AutomationId = "GC" };
gcButton.Clicked += (sender, args) =>
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
+ GarbageCollectionHelper.Collect();
if (_44166MDP.Counter > 0)
{
var collect = new Button() { Text = Collect };
collect.Clicked += (sender, args) =>
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
+ GarbageCollectionHelper.Collect();
};
Title = "Bugzilla 45722";
GCButton.Clicked += (sender, args) =>
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
+ GarbageCollectionHelper.Collect();
};
MessagingCenter.Subscribe<_45722Label>(this, _45722Label.CountMessage, sender =>
};
doGC.Clicked += (sender, e) => {
- GC.Collect ();
- GC.WaitForPendingFinalizers();
+ GarbageCollectionHelper.Collect();
instanceCount.Text = $"Instances: {_45926SecondPage.InstanceCounter.ToString()}";
messageCount.Text = $"Messages: {_45926SecondPage.MessageCounter.ToString()}";
};
async void Button_Clicked(object sender, EventArgs e)
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
+ GarbageCollectionHelper.Collect();
await Navigation.PushAsync(new ChildPage());
}
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);
async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new ListPage());
- GC.Collect();
+ GarbageCollectionHelper.Collect();
}
}
--- /dev/null
+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();
+ }
+ }
+}
AutomationId = "GC",
Command = new Command(o =>
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
+ GarbageCollectionHelper.Collect();
Label.Text = "Counter: " + Counter;
})
},
AutomationId = "GC",
Command = new Command(o =>
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
+ GarbageCollectionHelper.Collect();
Label.Text = "Counter: " + Counter;
})
},
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;
}
static Page CreateWeakReferencedPage()
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
+ GarbageCollectionHelper.Collect();
var result = CreatePage();
s_pageRefs.Add(new WeakReference(result));
Text = "Garbage Collection Things",
Command = new Command(() =>
{
- GC.Collect();
- GC.WaitForPendingFinalizers();
+ GarbageCollectionHelper.Collect();
AttachedStateEffects.Clear();
}),
},
// 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";
}
result.Text = "Click 'Push page' again";
return;
}
+
+ GarbageCollectionHelper.Collect();
result.Text = list[list.Count - 2].IsAlive ? "Failed" : "Success";
})
};
await Navigation.PushAsync(page);
await page.Navigation.PopAsync();
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
+ GarbageCollectionHelper.Collect();
list.Add(wref);
if (list.Count > 1)
<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" />
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
-</Project>
+</Project>
\ No newline at end of file