You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This may be a test quality issue, based on examining the test. I don't think it necessarily indicates a bug in crossgen. There is a suspicious codepath in the test that intentionally returns 100 which, if I understand the GC correctly, should never be reachable:
if(ans1==false){// GC.Collect() has already occurred..under GCStress
Console.WriteLine("Test for WeakReference.IsAlive passed!");
return100;
}
The test failure described in the original post indicates that the array pointed to by the weak reference is still alive after a single invocation of GC.Collect. My best guess for why this would happen is a dangling managed reference to the array at the point of the collection, but I'm not actually certain that the GC is obligated to get rid of the array under these circumstances even if it's unreachable?
When I run this test locally without crossgen involved at all, it fails:
PS Z:\runtime> Z:\runtime\artifacts\tests\coreclr\windows.x64.Debug\GC\API\WeakReference\IsAlive\IsAlive.cmd
BEGIN EXECUTION
"Z:\runtime\artifacts\tests\coreclr\windows.x64.Debug\Tests\Core_Root\corerun.exe" -p "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true" IsAlive.dll
True
True
Test for WeakReference.IsAlive failed!
Xunit.Sdk.EqualException: Assert.Equal() Failure: Values differ
Expected: 100
Actual: 1
at Xunit.Assert.Equal[T](T expected, T actual, IEqualityComparer`1 comparer) in /_/src/arcade/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs:line 174
at __GeneratedMainWrapper.Main()
Expected: 100
Actual: 101
if you induce a full blocking GC (which GC.Collect() does), GC is not in charge of determining what should be live at all. it just gets told by the rest of the runtime. so if the JIT tells the GC what that weakref points to is dead at the time of that GC, it's guaranteed that GC will null the target of the handle the weakref contains (which will cause IsAlive to return false); otherwise IsAlive will return true.
Activity
kg commentedon Jul 23, 2025
This may be a test quality issue, based on examining the test. I don't think it necessarily indicates a bug in crossgen. There is a suspicious codepath in the test that intentionally returns 100 which, if I understand the GC correctly, should never be reachable:
runtime/src/tests/GC/API/WeakReference/IsAlive.cs
Lines 34 to 37 in 7721695
The test failure described in the original post indicates that the array pointed to by the weak reference is still alive after a single invocation of GC.Collect. My best guess for why this would happen is a dangling managed reference to the array at the point of the collection, but I'm not actually certain that the GC is obligated to get rid of the array under these circumstances even if it's unreachable?
When I run this test locally without crossgen involved at all, it fails:
Maoni0 commentedon Jul 23, 2025
if you induce a full blocking GC (which
GC.Collect()does), GC is not in charge of determining what should be live at all. it just gets told by the rest of the runtime. so if the JIT tells the GC what that weakref points to is dead at the time of that GC, it's guaranteed that GC will null the target of the handle the weakref contains (which will causeIsAliveto return false); otherwiseIsAlivewill return true.