Skip to content

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

Merged
AaronRobinsonMSFT merged 2 commits into
dotnet:mainfrom
jkoritzinsky:forward-vtable-stubs-keepalive
May 4, 2023
Merged

Keep this alive across the native call for VTable-based source-generation#85723
AaronRobinsonMSFT merged 2 commits into
dotnet:mainfrom
jkoritzinsky:forward-vtable-stubs-keepalive

Conversation

@jkoritzinsky

@jkoritzinsky jkoritzinsky commented May 3, 2023

Copy link
Copy Markdown
Member

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

ghost commented May 3, 2023

Copy link
Copy Markdown

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