How to avoid fast memory increase during scavenge gc? How to avoid fast memory increase during scavenge gc? node.js node.js

How to avoid fast memory increase during scavenge gc?


You might try running your Node script with the option -–expose-gc:

node --expose-gc script.js

This allows to trigger the garbage collection manually from within JS:

global.gc();

When garbage collection is enforced manually, you can apply a multiple snapshot technique:

  • take one Snap before, one Snap after GC
  • then apply optimization
  • then one Snap before, one Snap after GC

The snapshots allow to track what causes the memory growth.The goal is to have a better result of the second "Snap after GC",when compared to the first "Snap after GC".


Best of my knowledge there is no simple way to see middle-aged content. However, if you see fast memory increase during scavenge and then sudden drop when mark&sweep takes place then this generally means that your code creates objects in large heap space. Long strings for example.

Rectify generates gigantic stack traces with each Error object which are large enough to not to fit into new space and therefore be ignored by mark&sweep.