-
Notifications
You must be signed in to change notification settings - Fork 1.4k
WeakReferenceMessenger automatic cleanup #4050
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
WeakReferenceMessenger automatic cleanup #4050
Conversation
Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
277b7ea
to
1254cb7
Compare
Marking this as ready for review - even if we managed to get dotnet/runtime#53296 approved, that'd still be a separate improvement for |
1254cb7
to
6c9fbd7
Compare
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.
Assuming all the internal changes are covered by the existing unit tests.
Assume that devs still calling Cleanup
are also still fine, this change is also now that it's OK if they don't?
{ | ||
/// <summary> | ||
/// Schedules a callback roughly every gen 2 GC (you may see a Gen 0 an Gen 1 but only once). | ||
/// Ported from https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Gen2GcCallback.cs. |
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.
wondering if we want to make this a permalink or pin to a certain release for historical reference/comparison in the future?
Otherwise since it's just .NET Foundation code as well, we should be fine with just a link from a license perspective. Though wonder if we want a separate thing to call out other .NET Foundation code we've been using somewhere... 🤔
@clairernovotny do other projects do this somehow that we can refer to? Since we're all the same organization under the same license I don't think there's a legal attribution we need to follow, but was just thinking it could be nice from an evangelism perspective.
Yup, though I've also just added one more test specifically for the automatic cleanup in d326912 just to be extra careful 😄
Exactly - it's not a breaking change and calling |
d326912
to
69f5b75
Compare
Hello @michael-hawker! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
@Sergio0694 there's a conflict here now. You want to resolve? |
Specifically the Unregister<TMessage, TToken> overload
69f5b75
to
e0a8335
Compare
@michael-hawker Done, should be good to review! 😄 |
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The
WeakReferenceMessenger
requires users to manually callCleanup()
to perform trimming of internal structures. This is inconvenient for consumers (When should they call this method? Why should they have to worry about this?), or at least, it would be more convenient if the whole behavior was just automatic.What is the new behavior?
This PR introduces automatic trimming, by leveraging a customized version of the
Gen2GcCallback
class to register a cleanup callback that will take care of trimming the messenger data structures if needed. Additionally this PR contains some improvements to nullability annotations, as well as one more minor performance improvements still withinWeakReferenceMessenger
.PR Checklist
Please check if your PR fulfills the following requirements:
Pull Request has been submitted to the documentation repository instructions. Link:Sample in sample app has been added / updated (for bug fixes / features)Icon has been created (if new sample) following the Thumbnail Style Guide and templatesOther information