Node.JS garbage collection event? or --trace-gc in stderr?

As a rule, when I write scripts, log messages always go to stderr and data (status messages, results from the algorithm, whatever) goes to stdout.

I would like to get this sent by stderr. It can be done?

It would be nice for me to use my own handler for some kind of process.on('gc') event, if any. There is one?

Right now I am writing code where stdout is reserved for data and I have no choice but to disable -trace-gc. I use memoryUsage() as the second best thing, but it doesn't talk about usage right before and right after the GC, it just tells you about usage whenever memoryUsage() called.

+4
source share
1 answer

A quick check of the v8 source code (where the garbage collector lives - [node src dir] /deps/v8/src/heap.cc and platform-posix.cc) shows that garbage collection messages are printed to the console using standard linux vprint () ( from printf (3)), so I'm sure you cannot catch them without fixing the source code.

+3
source

All Articles