如何启用增量式垃圾收集

如题. 我找到以下注释:

  • For a collection to be carried out incrementally the following conditions
  • must be met:
    • The collection must be run by calling JS::IncrementalGC() rather than
  • JS_GC().
    • The GC mode must have been set to JSGC_MODE_INCREMENTAL with
  • JS_SetGCParameter().
    • All native objects that have their own trace hook must indicate that they
  • implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS
  • flag.

IncrementalGC()应该在哪里调用

需要在 ScriptingCore::createGlobalContext 中添加下面的代码

JS_SetGCParameter(_rt, JSGCParamKey::JSGC_MODE, JSGC_MODE_INCREMENTAL);

非常感谢.我研究这个是觉得没准能解决GC中断时间过长的问题.

只修改这一句就可以了吗.是否还要手工加入对IncrementalGC() 的调用.

加这一句就可以了,Incremental GC 应该就会开启,但是影响比较细微

影响确实很细微:joy:,基本感觉不到

测试过了,确实如此.卡顿情况没有改善.