Hello,
I am using mozjs now. There is a question here, how can I know object is garbage collecting? For example global data.
In my application, i use JS::SetReservedSlot() to save user data to global data. But the user data is created by “new”. That means once global data is garbage collected, there will be memory leak. So I think if there is a function to tell when global data is garbage collected.
I find JS_AddFinalizeCallback(), but it seems it can’t tell a specified data is garbage collecting.
bool JS_AddFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb, void *data);
where “JSFinalizeCallback” has signature:
typedef void (JSFinalizeCallback)(JS::GCContext gcx, JSFinalizeStatus status, void data)*;
the “data” in “JS_AddFinalizeCallback” here will be used in “JSFinalizeCallback” as “data”.
Does it mean whenever any object is garbage collected, the “cb” will be invoked? If so, how do I know if the garbage collecting object is global data?
Thx