16

I'm writing a web server application using NodeJS 6.3.0. the application is executed with --expose-gc parameter, so I have the global.gc() function available. the question is how can I know when the manual execution of the garbage collector completed.

is global.gc() a synchronous function and that means that the next line of code will be executed when the function completed it task?

can I somehow monitor when my specific execution of garbage collector completed?

thanks!

ufk
  • 30,912
  • 70
  • 235
  • 386

1 Answers1

14

So I found this answer.

If you launch the node process with the --expose-gc flag, you can then call global.gc() to force node to run garbage collection. Keep in mind that all other execution within your node app is paused until GC completes, so don't use it too often or it will affect performance.

This one comments on it too.

Running global.gc() manually (enabled with node --expose_gc) would reduce memory usage by 50MB every time and would pause the app for about 400ms.

So it looks like it's synchronous and blocks until it is finished.

Community
  • 1
  • 1
carchase
  • 493
  • 6
  • 18