napi_finalize
用于插件提供的函数的函数指针类型,当外部拥有的数据准备好被清理时,会通知用户,因为与其相关联的对象已经被垃圾回收。用户必须提供一个满足以下签名的函数,当对象被回收时该函数会被调用。目前,可以使用 napi_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 with which 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, napi_finalize can be used for
finding out when objects that have external data are collected.
typedef void (*napi_finalize)(napi_env env,
void* finalize_data,
void* finalize_hint); 除非出于 对象生命周期管理 中讨论的原因,否则在函数体内创建 handle 和/或回调作用域并非必要。
🌐 Unless for reasons discussed in Object Lifetime Management, creating a handle and/or callback scope inside the function body is not necessary.