To request the Garbage Collector in node.js to run with Node.js, we call the global.gc
method.
For instance, we write
try {
global?.gc?.();
} catch (e) {
console.log("`node --expose-gc index.js`");
process.exit();
}
to call global.gc
to request the garbage collector if it’s available.
We make the garbage collection available with the --expose-gc
flag.