From a8e7180c7148661759a7dde7e227107ee23aea43 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 26 Jun 2026 12:12:50 +0000 Subject: [PATCH 1/2] Initial plan From 85909993f8ee704366c9f197800a264c59e9d76c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 26 Jun 2026 12:41:02 +0000 Subject: [PATCH 2/2] Adjust NativeAOT tolerance in DoNotLeakWeakReferences test Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com> --- .../Mono.Android-Tests/Java.Interop/JnienvTest.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs index 1e23c37907d..933a376b994 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs @@ -520,10 +520,15 @@ public void DoNotLeakWeakReferences () // `Runtime.GetSurfacedObjects()` is process-global: NUnit/MTP // infrastructure (per-test TestExecutionContext, listeners, Console // capture, etc.) creates and releases transient Java.Lang.Object - // peers around every test, so the count drifts by a few entries - // between the snapshots below. Allow a small tolerance instead of - // requiring an exact count -- a real leak would dwarf this. - const int tolerance = 10; + // peers around every test, so the count drifts between snapshots. + // + // NativeAOT currently has a higher transient object count, so allow + // a wider tolerance there while keeping stricter checks elsewhere. + const int defaultTolerance = 10; + const int nativeAotTolerance = 30; + int tolerance = AppContext.TryGetSwitch ("Microsoft.Android.Runtime.RuntimeFeature.IsNativeAotRuntime", out bool isNativeAotRuntime) && isNativeAotRuntime + ? nativeAotTolerance + : defaultTolerance; WeakReference r = null; Exception threadException = null;