-
-
Notifications
You must be signed in to change notification settings - Fork 670
[Feature Request] Support for @destructor #383
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
Comments
Should be doable, yeah, and there are certainly use cases where it makes sense to communicate destruction of a managed object to the host. |
There seems to be more general need for a this in the new runtime. For example, a class which holds references to unmanaged classes and uses the destructor method to manually free them. |
Currently my use case is solved by using rtrace. |
I think this is still a great feature request, even if your specific use case is taken care of |
I still have software that would benefit from a destructor. But I have ways of working around not having it. |
Old issue, but still relevant :) My use case for destructors is WASI APIs, or more generally any external API that obtains opaque handles, that eventually have to be closed. The current workaround is to use unmanaged objects and expect applications to explicitly destroy them, but this is not super convenient. |
Created a little experiment linked above that might help to inform future design. |
@jedisct1 It might also be nice to have something like |
With finalizer will be possible simple block scoping: function readDataFrom(path: string): ArrayBuffer {
let data: ArrayBuffer;
{
let fr = new FileReader(path);
data = fr.readAll();
// implicitly call FileReader#finalizer which close FileReader
}
return data;
} |
Closing this issue as part of 2020 vacuum because destructors turned out to be not feasible very likely, but I opened a new issue tracking the road ahead. |
I have a use case for creating objects in AssemblyScript that would benefit from a callback being called when they are garbage collected or destroyed. Of course javascript doesn't actually have destructors, and you can't tell when an object is being collected. However, if I could keep track of which objects were deleted, I could use a callback to communicate with my module consumer to notify them an internal object was collected.
This is just a simple example, utilizing the decorator syntax:
I don't know if this idea is good, or worth pursuing, but I just wanted to share it somewhere constructive to get feedback. Thanks for all your hard work on this amazing project!
The text was updated successfully, but these errors were encountered: