JSFinalizeOp 编辑
JSFinalizeOp
is the type of JSClass.finalize
.
Syntax
typedef void (* JSFinalizeOp)(JSFreeOp *fop, JSObject *obj);
Name | Type | Description |
---|---|---|
cx | JSContext * | The JS context in which garbage collection is taking place. |
obj | JSObject * | The object being destroyed. |
Description
The JSFinalizeOp
is analogous to Java finalizers or C++ destructors. The garbage collector calls this callback for each object it collects. The finalizer's job is to clean up any resources allocated by the instance which wouldn't normally be cleaned up by the garbage collector (private data stored in the object by the application, file handles, etc.)
Finalizers must never store a reference to obj
.
Warning: This hook is called during garbage collection. Any JSAPI call that would allocate memory from the GC heap will fail if called from a finalizer.
For other ways to interact with garbage collection (e.g. implementing weak references), see JS_SetGCCallback
.
JSClass hooks
JSClass offers the following hook:
The
JSClass.finalize
callback is a hook for destructor code. The garbage collector calls thefinalize
hook of eachJSObject
it collects.
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论