WeakReferenceList behavior maybe no safe
Open
Bug
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
This is the code.
https://github.com/dotnet/wpf/blob/87115e5b0efade5ec32379264e9909d11b01a9e4/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/WeakReferenceList.cs#L187-L189
And as we can see, the code check the WeakReference is alive and then get the Target. But the GC will collect the object before we get the Target and after we check the IsAlive.
And I think we should use the TryGetTarget to get the value.
Thank you.
Contributor guide
Assessment
This issue has not been assessed yet.