node_api_basic_finalize


稳定性: 1 - 实验性的

¥Stability: 1 - Experimental

附加提供的函数的函数指针类型,允许用户在外部拥有的数据准备好清理时收到通知,因为与其关联的对象已被垃圾收集。用户必须提供满足以下签名的函数,该函数将在对象的集合上调用。目前,node_api_basic_finalize 可用于查明何时收集具有外部数据的对象。

¥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.

由于这些函数可能会在 JavaScript 引擎处于无法执行 JavaScript 代码的状态时被调用,因此只能调用接受 node_api_basic_env 作为其第一个参数的 Node-API。node_api_post_finalizer 可用于安排需要访问 JavaScript 引擎状态的 Node-API 调用,以便在当前垃圾收集周期完成后运行。

¥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.

对于 node_api_create_external_string_latin1node_api_create_external_string_utf16env 参数可以为空,因为在环境关闭的后期可以收集外部字符串。

¥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:

  • 实验(NAPI_EXPERIMENTAL):

    ¥experimental (NAPI_EXPERIMENTAL):

    只能调用接受 node_api_basic_env 作为第一个参数的 Node-API 调用,否则应用将终止并显示相应的错误消息。可以通过定义 NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT 来关闭此功能。

    ¥Only Node-API calls that accept a node_api_basic_env as their first parameter may be called, otherwise the application will be terminated with an appropriate error message. This feature can be turned off by defining NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT.