Files
Dan Siegel a78384d5fb test: reproduce retained observer and desktop lifetimes
Unchanged master: observer fixture has 2 collection failures and 2 passing controls; WPF lifetime fixtures have 5 failures and 4 passing controls. Covers abandoned tracker, disposed-manager collection, loader replacement, disposal order, late callbacks and nested observer recreation.

# Conflicts:
#	tests/Avalonia/Prism.Avalonia.Tests/Prism.Avalonia.Tests.csproj
#	tests/Wpf/Prism.Wpf.Tests/Prism.Wpf.Tests.csproj
2026-10-14 06:21:55 -06:00

26 lines
629 B
C#

using System;
using System.Runtime.CompilerServices;
using Xunit;
namespace Prism.Tests.Lifetime;
internal static class CollectionProbe
{
// Read weak targets only after all collections, outside the lifetime helper.
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Collect()
{
for (var i = 0; i < 3; i++)
{
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
GC.WaitForPendingFinalizers();
}
}
internal static void Collected(WeakReference reference)
{
Collect();
Assert.False(reference.IsAlive);
}
}