Closed
Description
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:
declare function notify_collected(ref: vec_3): void;
class vec_3 {
x: f64;
y: f64;
z: f64;
@destructor
protected __some_func_name() {
notify_collected(this);
}
}
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!