Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when i manually execute the garbage collector, how can I tell when it's completed?

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!

like image 716
ufk Avatar asked Jul 07 '16 09:07

ufk


People also ask

How do you make sure that the garbage collector is done running when you call GC collect ()?

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.

Can you manually call the garbage collector?

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.

How do I know if my GC is running?

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.

What is garbage collection time?

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.


1 Answers

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.

like image 164
carchase Avatar answered Sep 22 '22 05:09

carchase