-
Notifications
You must be signed in to change notification settings - Fork 107
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
Conversation
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.
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)); |
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.
Technically I think ABI.System.Nullable would have handled keeping the objref alive I think, but this doesn't hurt either.
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.