dotnet / dotnet/wpf

WeakReferenceList behavior maybe no safe

Open
#3,012 1 comment 6 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.