Skip to content
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

Ujjwalchadha/fix value type caching 2 #980

Merged
merged 5 commits into from
Aug 31, 2021

Conversation

ujjwalchadha
Copy link
Contributor

This PR reverts the previous fix to value type caching issue.
The actual cause of the issue is: not holding on to the native value type (coming in as IReference or IReferenceArrsy) when it gets stored in the dotnet cache. Thus, the pointer is allowed to be reused before GC cleans it.
We fix it by adding a ConditionalWeakTable which holds on to the native reference until the boxed value is alive. Thus not allowing pointer reuse before it should be.

@ujjwalchadha ujjwalchadha linked an issue Aug 31, 2021 that may be closed by this pull request
Copy link
Member

@jkoritzinsky jkoritzinsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks good to me.

Can you also add calls to CreateReferenceCachingFactory for the

if (runtimeClassName == "Windows.Foundation.IReference`1<String>")

and

if (runtimeClassName == "Windows.Foundation.IReference`1<Windows.UI.Xaml.Interop.TypeName>")

cases above? We'll need this check there as well to cover all cases.

@@ -312,11 +324,11 @@ private static bool IsIReferenceArray(Type implementationType)
// PropertySet and ValueSet can return IReference<String> but Nullable<String> is illegal
if (runtimeClassName == "Windows.Foundation.IReference`1<String>")
{
return (IInspectable obj) => new ABI.System.Nullable<String>(obj.ObjRef);
return CreateReferenceCachingFactory((IInspectable obj) => new ABI.System.Nullable<String>(obj.ObjRef));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically I think ABI.System.Nullable would have handled keeping the objref alive I think, but this doesn't hurt either.

@ujjwalchadha ujjwalchadha merged commit c9b8e38 into master Aug 31, 2021
@ujjwalchadha ujjwalchadha deleted the ujjwalchadha/fix_value_type_caching_2 branch August 31, 2021 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WinUI padding test failure
3 participants