How to "free" memory Buffer from Garbage Collector in Node.js? How to "free" memory Buffer from Garbage Collector in Node.js? express express

How to "free" memory Buffer from Garbage Collector in Node.js?


If you are really confident what your code has no leaks, and you already set every big variable to null, then you can try to start GC.

Add option --expose-gc when you are running you script:

node --expose-gc index.js

And whenever you want inside of you scripts u can call GC:

global.gc()

But I strongly recommend you to find some ways to do it without forcing GC.

Good luck!


First, the module that you are using seems to cause a lot of overhead for 75k rows, wouldn't it be better to use CSV format instead?

If you do want to continue with your approach, there some V8 options that can restrict some memory limits. Restricting the memory limits could cause more time wasted on doing garbage collecting, so be careful with over optimising.

Here is good place to start with: Limit Node.js memory usage to less than 300MB per process