You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Do you have examples of code that trigger would trigger the warnings? (CA2000, CA1001, CA2213)? Looking for examples that solve the issue so can demonstrate, why you would need these warnings and the solution in the readme.
usingDemoWorld.wit.imports;staticclassFoo{staticvoidCA2000(){varresource=newIDemoImports.DemoResource();// Warning CA2000 : Call System.IDisposable.Dispose on object created// by 'new IDemoImports.DemoResource()' before all references to it are// out of scope}}classCA1001// Warning CA1001 : Type 'CA1001' owns disposable field(s) '_resource' but is// not disposable{privatereadonlyIDemoImports.DemoResource?_resource=new();}classCA2213:IDisposable// Warning CA2213 : 'CA2213' contains field '_resource' that is of IDisposable// type 'DemoResource?', but it is never disposed. Change the Dispose method on// 'CA2213' to call Close or Dispose on this field{privatereadonlyIDemoImports.DemoResource?_resource=new();publicvoidDispose(){}}
Activity
yowl commentedon Nov 17, 2024
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 commentedon Nov 19, 2024
Okay, never mind, this seems to be intended: bytecodealliance/wit-bindgen@c648fc7
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 commentedon Nov 19, 2024
You are right, I'd forgotten about the child resources problem.
jsturtevant commentedon Nov 26, 2024
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.
kaivol commentedon Mar 12, 2025
Sorry, I missed your reply.
Examples of what exactly do you mean?
jsturtevant commentedon Mar 12, 2025
Do you have examples of code that trigger would trigger the warnings?
(CA2000, CA1001, CA2213)?Looking for examples that solve the issue so can demonstrate, why you would need these warnings and the solution in the readme.kaivol commentedon Mar 14, 2025
Sure thing:
WIT file:
jsturtevant commentedon Mar 20, 2025
Thanks! I will see if we can add these warnings to the new template at some point so can help inform users of the pitfalls.