-
Notifications
You must be signed in to change notification settings - Fork 983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor WeakRefCollection
to replace ArrayList
with List<T>
#10281
Conversation
@halgab could you please give this a quick review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to help!
I just see a minor potential improvement.
I don;t know if you've noticed, but this type is also defined here. I don't know if code consolidation between the winforms projects and System.Drawing.Common is something that should be considered, knowing that the latter targetting netfx makes it less profitable.
Other open questions I have about this type (but that are outside the scope of this PR):
- should this be made generic?
- if that's the case, should we be using
WeakReference<T>
under the hood? And more generally should we try and replaceWeakReference
with its generic counterpart across codebase?
return null; | ||
} | ||
set => InnerList[index] = CreateWeakRefObject(value); | ||
get => InnerList[index] is WeakRefObject weakRef && weakRef.IsAlive ? weakRef.Target : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get => InnerList[index] is WeakRefObject weakRef && weakRef.IsAlive ? weakRef.Target : null; | |
get => InnerList[index].Target; |
According to the WeakReference
docs, Target
returns null if IsAlive
is false
@elachlan I don't think there is any real difference between the two It would also be worth looking at whether these can be typed. Can this be |
@JeremyKuhne what namespace do you want me to use if we merge them? |
@elachlan you can just put this in |
Closing in favor of #10291 |
Related: #8140
Microsoft Reviewers: Open in CodeFlow