I have a self-defined class that calls a native method to allocate buffer in the constructor method, like below:
MyClass = function () {
this.buffer = native.alloc()
}
The buffer has to be released when the instance of MyClass is being deleted. Can I define a destructor in javascript like below? Would it be invoked when the GC happens?
MyClass.prototype.destructor = function () {
native.free(this.buffer)
}