node_api_basic_finalize
callbackexperimentaljs_native_api.hFunction pointer type for add-on provided functions that allow the user to be notified when externally-owned data is ready to be cleaned up because the object it was associated with has been garbage-collected.
Stability: 1 - Experimental
Function pointer type for add-on provided functions that allow the user to be
notified when externally-owned data is ready to be cleaned up because the
object it was associated with has been garbage-collected. The user must provide
a function satisfying the following signature which would get called upon the
object's collection. Currently, node_api_basic_finalize can be used for
finding out when objects that have external data are collected.
typedef void (*node_api_basic_finalize)(node_api_basic_env env,
void* finalize_data,
void* finalize_hint);
Unless for reasons discussed in Object Lifetime Management, creating a handle and/or callback scope inside the function body is not necessary.
Since these functions may be called while the JavaScript engine is in a state
where it cannot execute JavaScript code, only Node-APIs which accept a
node_api_basic_env as their first parameter may be called.
node_api_post_finalizer can be used to schedule Node-API calls that
require access to the JavaScript engine's state to run after the current
garbage collection cycle has completed.
In the case of node_api_create_external_string_latin1 and
node_api_create_external_string_utf16 the env parameter may be null,
because external strings can be collected during the latter part of environment
shutdown.
Change History:
-
experimental (
NAPI_EXPERIMENTAL):Only Node-API calls that accept a
node_api_basic_envas their first parameter may be called, otherwise the application will be terminated with an appropriate error message. This feature can be turned off by definingNODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT.