Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
WeakReference behaves differently from .NET Framework. #12847
I am porting NHibernate to .NET Core (nhibernate/nhibernate-core#633), and some of the tests related to
The same tests have been running on .NET Framework.
Please see the example test here: https://github.com/ngbrown/coreclr-WeakReferenceTest
passes, while running:
I think the summary is that weak references don't appear to actually be getting freed like they should be during garbage collection. This means we can't be sure that our query cache (which
I wasn't 100% sure where to put this issue, because coreclr implements
From those tests, they sometimes did these three calls before checking stuff:
GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect();
but changing to that from a single
The JIT has been always extending the lifetime of the local and temp variables in some cases - the spec allows that. It started doing it in more cases after change #9231.
We had tests that used to depend on the exact lifetime tracking as well that needed updating after this change, e.g. dotnet/corefx#16595 .
table[new object()] = new object(); table[new object()] = new object();
lines into their own non-inlined method so that the JIT doesn't have the ability to extend beyond the lifetime of the method any temporaries keeping those objects alive.
@ngbrown Here's a PR where I fixed some of CoreCLR's own tests that were running into trouble with the Collect/WaitForPendingFinalizers/Collect pattern: #11216. Unfortunately these sorts of tests are racy in general due to the asynchrony of finalization but the fixes I made in that PR seem to have fixed the tests (in addition to @stephentoub 's suggestion)