21

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?

9
  • Hmmm, will this work for you? Commented Oct 29, 2015 at 7:43
  • Not really. This will trigger non-incremental major GC runs (mark-sweep-compact) which are pretty heavy and introduce long delays in comparison to fast incremental runs. Rather than running GC myself, I'd like to block GC for some time and release it again to normal operation. Commented Oct 29, 2015 at 14:17
  • I would recommend raising this question as a bug in Node.js repo and v8 mailing list. Commented Oct 29, 2015 at 17:26
  • I have the same problem. Have you found a solution? Commented Jan 30, 2017 at 22:36
  • Question, do you need to allocate memory during that time? Commented Feb 13, 2017 at 18:31

2 Answers 2

5
+100

As far as I know you can't manually stop v8's garbage collector, the only thing you can do is start the gc process manually running global.gc() but not stopping v8's process.

Sign up to request clarification or add additional context in comments.

Comments

4

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.