[release/5.0] WinRT Reference Tracker memory fixes - #51421
Merged
Conversation
Found during new ComWrappers aggregation API in .NET 6.
It is possible that a Reference Tracker runtime can QI a managed object wrapper when it has been marked as Destroyed or the associated managed object has been collected. The QI impl must safely ensure prior to performing the QI that the GC hasn't collected the wrapped managed object.
ComWrappers API test passes GCStress=0xf
jeffschwMSFT
approved these changes
Apr 19, 2021
jeffschwMSFT
left a comment
Member
There was a problem hiding this comment.
Approved. I will take for consideration in 5.0.x
track down an issue for C#/WinRT.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Runtime follow up fixes for .NET 5 - #45622 and microsoft/CsWinRT#782
Description
The following PR is for rare but not uncommon scenarios in the WinUI interactions with .NET. The C#/WinRT has been able to mitigate some of the following issues but they can still occur and results in leaks or a destabilized application environment.
QueryInterface.QueryInterfacescenario.Once this work is in it will be ported to .NET 6.
Customer Impact
Possible crashing behavior when a Reference Tracker runtime (Xaml) performs a
QueryInterfaceon a collected managed object. Memory leak in an uncommon scenario involving breaking circular references using the .NET GC.Regression
This API is new in .NET 5.0 and these issues have existed since original implementation. However the API is used to address the removal of WinRT built-in support - #37672.
Testing
The C#/WinRT and WinUI teams have signed off on these changes using a private build of the runtime. Additional runtime testing for the fixed behavior in this PR has also been added.
Risk
These changes only impact WinRT scenarios and represent no risk in all other scenarios.
/cc @davidwrighton @Scottj1s @manodasanW @MikeHillberg @jkoritzinsky @elinor-fung