destroy(asyncId)
asyncId<number>
在与 asyncId 对应的资源被销毁后调用。它也会异步地从嵌入器 API emitDestroy() 调用。
🌐 Called after the resource corresponding to asyncId is destroyed. It is also
called asynchronously from the embedder API emitDestroy().
有些资源依赖垃圾回收来进行清理,因此如果对传递给 init 的 resource 对象进行了引用,destroy 可能永远不会被调用,从而导致应用的内存泄漏。如果该资源不依赖垃圾回收,那么这就不会成为问题。
🌐 Some resources depend on garbage collection for cleanup, so if a reference is
made to the resource object passed to init it is possible that destroy
will never be called, causing a memory leak in the application. If the resource
does not depend on garbage collection, then this will not be an issue.
使用 destroy 钩子会导致额外的开销,因为它使垃圾回收器能够追踪 Promise 实例。
🌐 Using the destroy hook results in additional overhead because it enables
tracking of Promise instances via the garbage collector.