Preventing Garbage Collection in the Spidermonkey Javascript Engine

无人久伴 提交于 2019-12-12 03:34:27

问题


According the Spidermonkey's User Guide

https://developer.mozilla.org/En/SpiderMonkey/JSAPI_User_Guide

... a jsval by itself does not protect its referent from the garbage collector...

My understanding of this statement is that if we create a JSString by, say, JS_NewStringCopyZ(), the value returned can be gc'ed at anytime. e.g.

JSString *str=JS_NewStringCopyZ(cx, "hello world");
JS_GC(cx);
//..now my "hello world" JSString is gone

So how do we prevent the str above from being gc'ed? I notice there is a JS_EnterLocalRootScope () function that I can call at the start of my JSNative function. Unfortunately, it is now deprecated. Then what should be the proper way to prevent gc?


回答1:


I think this is a duplicate of Garbage collector issues on spidermonkey… JS_AnchorPtr()? -- the answer there shows how to anchor pointers to keep them live across a GC when using SpiderMonkey as a shared library. If that doesn't answer your question, please edit to clarify.



来源:https://stackoverflow.com/questions/10482303/preventing-garbage-collection-in-the-spidermonkey-javascript-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!