JS_AddFinalizeCallback 编辑

This article covers features introduced in SpiderMonkey 17

Add/remove callback function for finalization.

Syntax

bool
JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data); // Added in SpiderMonkey 38 (JSAPI 32)

void
JS_RemoveFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); // Added in SpiderMonkey 38 (JSAPI 32)

void
JS_SetFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb); // Obsolete since JSAPI 32
NameTypeDescription
rtJSRuntime *The JSRuntime for which to set the finalization callback.
cbJSFinalizeCallbackPointer to the new callback function to use.
datavoid *Passed to data parameter for JSFinalizeCallback.

Callback syntax

typedef enum JSFinalizeStatus {
    JSFINALIZE_GROUP_START,
    JSFINALIZE_GROUP_END,
    JSFINALIZE_COLLECTION_END
} JSFinalizeStatus;

typedef void
(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, bool isCompartment, void *data);
NameTypeDescription
fopJSFreeOp *A pointer to an instance of JSFreeOp.
statusJSFinalizeStatusOne of the JSFinalizeStatus constants, described below, indicating the stage of finalize.
isCompartmentboolfalse if all compartments are being collected, true if a compartment is being collected.
datavoid *data parameter specified in JS_AddFinalizeCallback. Added in SpiderMonkey 38
NameDescription
JSFINALIZE_GROUP_STARTCalled when preparing to sweep a group of compartments, before anything has been swept. The collector will not yield to the mutator before calling the callback with JSFINALIZE_GROUP_END status.
JSFINALIZE_GROUP_ENDCalled when preparing to sweep a group of compartments. Weak references to unmarked things have been removed and things that are not swept incrementally have been finalized at this point. The collector may yield to the mutator after this point.
JSFINALIZE_COLLECTION_ENDCalled at the end of collection when everything has been swept.

Description

JS_AddFinalizeCallback add a callback function which the garbage collector calls at several points during garbage collection. rt is the runtime in which you specify the callback. cb is a pointer to the callback function to add.

JS_RemoveFinalizeCallback removes the previously added callback function.

Obsolete since JSAPI 32

JS_SetFinalizeCallback sets a new callback function. It was replaced with JS_AddFinalizeCallback, to allow adding multiple callback functions.

See Also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:115 次

字数:6148

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文