node --expose-gc script.js

Category: Node.js & npm/yarn

node --expose-gc script.js

Expose the global garbage collector

Adds the global gc() function so scripts can force garbage collection, mainly for memory tests and benchmarking. Without the flag gc is undefined and throws. Combine with --max-old-space-size to control heap size during tests.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.