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!
To have the garbage collector consider all objects regardless of their generation, use the version of this method that takes no parameters. To have the garbage collector reclaim objects based on a GCCollectionMode setting, use the GC. Collect(Int32, GCCollectionMode) method overload.
The GC can honor a manual call; for example, through the System. gc() call. This call nearly always starts a garbage collection cycle, which is a heavy use of computer resources.
For example, running "jstat –gc <vmid> 1000" (or 1s) will display the GC monitoring data on the console every 1 second. "jstat –gc <vmid> 1000 10" will display the GC monitoring information once every 1 second for 10 times in total.
The more live objects are found, the longer the suspension, which has a direct impact on response time and throughput. This fundamental tenet of garbage collection and the resulting effect on application execution is called the garbage-collection pause or GC pause time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With