-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
Milestone
Description
WeakReference has a special codepath in GC to finalize eagerly, which avoids using finalizer queue. We could easily do that in NativeAOT as well, if we could tell if an instance is a WeakReference or WeakReference<T>
Weak references could be used in big quantities, so such optimization would be a noticeable improvement.
There is also a subtle correctness issue.
If, for example, a weakref getter runs concurrently with finalizer and the handle gets recycled for an object of a different type, it could result in a GC hole.
On the other hand eager finalization is run by GC when objects transition from Reachable to F-Reachable. There is no way for that to happen concurrently with getter, so handle recycling is not a problem.