bytecodealliance / componentize-dotnet

Tooling for creating WebAssembly components from C#
Apache License 2.0
42 stars 9 forks source link

Imported Resources don't provide a finalizer #58

Open kaivol opened 1 week ago

kaivol commented 1 week ago

Currently, projections for imported resources implement IDisposable, but they do not provide a finalizer. This means that if the user forgets to manually dispose the resource, its [resource-drop] function is never called.

I believe this is incorrect, and the resource should provide a finalizer that calls the resource's [resource-drop] function.


Version:

<PackageReference Include="BytecodeAlliance.Componentize.DotNet.Wasm.SDK" Version="0.4.0-preview00007" />
yowl commented 1 week ago

Seems like a bug, but with wit-bindgen, rather than this tooling, so should be https://github.com/bytecodealliance/wit-bindgen/issues I think

kaivol commented 1 week ago

Okay, never mind, this seems to be intended: https://github.com/bytecodealliance/wit-bindgen/commit/c648fc7b84dea32e66f87b760832b7f7a79dd63c

Nevertheless, it might be helpful to mention in the readme that resources must be disposed/dropped manually. Perhaps recommending to enable the corresponding warnings (CA2000, CA1001, CA2213)?

Feel free to close this issue if this is not the correct repository for these suggestions.

yowl commented 1 week ago

You are right, I'd forgotten about the child resources problem.

jsturtevant commented 8 hours ago

The warnings look reasonable to turn on, Do you have an example where this triggers?

Not sure the best place to document, but we can certainly add a note the readme here.