napi_add_finalizer
functionv5js_native_api.hAdds a napi_finalize callback which will be called when the JavaScript object in js_object has been garbage-collected.
napi_status napi_add_finalizer(napi_env env,
napi_value js_object,
void* finalize_data,
node_api_basic_finalize finalize_cb,
void* finalize_hint,
napi_ref* result);
[in] env: The environment that the API is invoked under.[in] js_object: The JavaScript object to which the native data will be attached.[in] finalize_data: Optional data to be passed tofinalize_cb.[in] finalize_cb: Native callback that will be used to free the native data when the JavaScript object has been garbage-collected.napi_finalizeprovides more details.[in] finalize_hint: Optional contextual hint that is passed to the finalize callback.[out] result: Optional reference to the JavaScript object.
Returns napi_ok if the API succeeded.
Adds a napi_finalize callback which will be called when the JavaScript object
in js_object has been garbage-collected.
This API can be called multiple times on a single JavaScript object.
Caution: The optional returned reference (if obtained) should be deleted via
napi_delete_reference ONLY in response to the finalize callback
invocation. If it is deleted before then, then the finalize callback may never
be invoked. Therefore, when obtaining a reference a finalize callback is also
required in order to enable correct disposal of the reference.