0

This question asks what the various values returned by v8.getHeapStatistics() are, but I'm still not clear what the units are.

I would expect the units of those relating to memory/heap size to all be bytes.

However, I'm trying to debug an apparent memory leak in a NodeJS app, and am periodically writing out the used_heap_size as a percentage of the total_available_size to see how quickly the heap fills up, and I'm seeing some very odd output.

The heap apparently gets to just over 10,000% (yes, ten thousand percent) full before the app crashes with:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

So either I'm misunderstanding the relationship between used_heap_size and total_available_size, or else they don't have the same units. (Or there's conceivably a bug, I suppose.)

The docs say that they're both numbers, which is only helpful to a point.

Am I making an incorrect assumption? Am I misunderstanding the values?

trincot
  • 317,000
  • 35
  • 244
  • 286
IpsRich
  • 797
  • 10
  • 23
  • 10,000 is 100 squared. Is there any chance this is a bug on your side and you're multiplying by 100 twice? – Mureinik Jun 07 '23 at 09:01
  • Thanks @Mureinik :-) Yes, I did wonder that myself actually! I'm always paranoid about posting questions here where I've been daft, so I checked, and the percentage is calculated thus: `const mem = v8.getHeapStatistics(), percentage = Math.round( (100 * mem.used_heap_size) / mem.total_available_size );`. – IpsRich Jun 07 '23 at 09:21

0 Answers0