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

Keep this alive across the native call for VTable-based source-generation #85723

Merged

Conversation

jkoritzinsky
Copy link
Member

@jkoritzinsky jkoritzinsky commented May 3, 2023

Otherwise another thread can GC the managed object and cause the underlying native memory to be released mid-call.

This PR adds a GC.KeepAlive(this); call after the call to native code where we put the GC.KeepAlive() calls for marshalling delegates.

@jkoritzinsky jkoritzinsky added area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature labels May 3, 2023
@jkoritzinsky jkoritzinsky added this to the 8.0.0 milestone May 3, 2023
@ghost ghost assigned jkoritzinsky May 3, 2023
@ghost
Copy link

ghost commented May 3, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Otherwise another thread can GC the managed object and cause the underlying native memory to be released mid-call.

Author: jkoritzinsky
Assignees: -
Labels:

area-System.Runtime.InteropServices, source-generator

Milestone: 8.0.0

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 91cdf05 into dotnet:main May 4, 2023
@jkoritzinsky jkoritzinsky deleted the forward-vtable-stubs-keepalive branch May 4, 2023 17:44
@ghost ghost locked as resolved and limited conversation to collaborators Jun 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants