Skip to content

Commit

Permalink
Fix GC Race condition with tests (#27652)
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen authored Feb 9, 2025
1 parent 2075725 commit e6c62d6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Controls/tests/Core.UnitTests/TestClasses/TestWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Maui.Controls.Core.UnitTests
{
public class TestWindow : Window
{
// Because the relationship from Window => Application is a weakreference
// we need to retain a reference to the Application so it doesn't get GC'd
TestApp _app;
public TestWindow()
{

Expand All @@ -24,12 +25,10 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
if (propertyName == PageProperty.PropertyName &&
Parent == null)
{
var app = new TestApp(this);
_ = (app as IApplication).CreateWindow(null);
_app = new TestApp(this);
_ = (_app as IApplication).CreateWindow(null);
}
}


}

public static class TestWindowExtensions
Expand Down

0 comments on commit e6c62d6

Please # to comment.