简体   繁体   中英

Disable node.js garbage collection for a while

Is there any way to explicitly disable GC runs (at least most time-consuming ones, like GC interrupts in old space) during the specified period of time, while executing some code sensitive to delays? Something like this:

disableGc();
runCodeWithoutDelays();
enableGc();

Probably using some node options, or native modules? Or can I write my own module, is there an API in V8 for that?

据我所知,你无法手动停止v8的垃圾收集器,你唯一能做的就是手动运行global.gc()启动gc进程,但不要停止v8的进程。

Another person had the same question and published an issue on GitHub here: https://github.com/nodejs/help/issues/462

Answer is you can't disable the GC in Node, but you can at least tweak the memory options to use the max space available and delay GC, by using --max_old_space_size, --max-semi-space-size.

An example is provided there in context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM