Skip to content

C#: do not drop resource handles in finalizers#1040

Merged
alexcrichton merged 2 commits intobytecodealliance:mainfrom
dicej:csharp-no-drop-in-finalizers
Aug 29, 2024
Merged

C#: do not drop resource handles in finalizers#1040
alexcrichton merged 2 commits intobytecodealliance:mainfrom
dicej:csharp-no-drop-in-finalizers

Conversation

@dicej
Copy link
Copy Markdown
Collaborator

@dicej dicej commented Aug 29, 2024

As of this writing, we cannot safely drop a handle to an imported resource from a .NET finalizer because it may still have one or more open child resources. Once WIT has explicit syntax for indicating parent/child relationships, we should be able to use that information to keep track of child resources automatically in generated code, at which point we'll be able to drop them in the correct order from finalizers.

Fixes #1039

As of this writing, we cannot safely drop a handle to an imported resource from
a .NET finalizer because it may still have one or more open child resources.
Once WIT has explicit syntax for indicating parent/child relationships, we
should be able to use that information to keep track of child resources
automatically in generated code, at which point we'll be able to drop them in
the correct order from finalizers.

Fixes bytecodealliance#1039

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
dicej added a commit to dicej/runtimelab that referenced this pull request Aug 29, 2024
See bytecodealliance/wit-bindgen#1040

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
dicej added a commit to dicej/spin-dotnet-sdk that referenced this pull request Aug 29, 2024
See bytecodealliance/wit-bindgen#1040

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@alexcrichton alexcrichton added this pull request to the merge queue Aug 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 29, 2024
@alexcrichton alexcrichton added this pull request to the merge queue Aug 29, 2024
Merged via the queue into bytecodealliance:main with commit c648fc7 Aug 29, 2024
francomattar added a commit to francomattar/spin-sdk-dotnet that referenced this pull request Dec 13, 2024
See bytecodealliance/wit-bindgen#1040

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
artemsuvorov3 added a commit to artemsuvorov3/artem-spin-dotnet-sdk that referenced this pull request Jan 8, 2025
See bytecodealliance/wit-bindgen#1040

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
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.

C#: the generated finalization logic does not take child resources into account

3 participants