Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 202
artch Avatar asked Oct 29 '15 07:10

artch


People also ask

Can you disable garbage collection?

Since the collector supplements the reference counting already used in Python, you can disable the collector if you are sure your program does not create reference cycles. Automatic collection can be disabled by calling gc. disable() .

Does Nodejs have garbage collection?

Luckily for you, Node. js comes with a garbage collector, and you don't need to manually manage memory allocation.

Is Garbage collection in JavaScript automatic?

Some high-level languages, such as JavaScript, utilize a form of automatic memory management known as garbage collection (GC).

What is the event loop in Nodejs?

The event loop is what allows Node. js to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded — by offloading operations to the system kernel whenever possible. Since most modern kernels are multi-threaded, they can handle multiple operations executing in the background.


1 Answers

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.

like image 119
Joan Miquel Avatar answered Sep 21 '22 13:09

Joan Miquel