V8 Heap Size Limit

Viewed 475

I have a simple Node method that allocates an array:

function allocateArray(size) {
    let arr = Array(size).fill('Hello World');

    console.log(`Array size: ${arr.length}`);
    console.log(v8.getHeapStatistics());
    console.log();
}

allocateArray(1e7);

When I run the script with the command node --max-heap-size=16 test.js, I'm presented with the following heap statistics, which seems that the used heap size is much higher than the heap size limit:

Array size: 10000000
{
  total_heap_size: 85463040,
  total_heap_size_executable: 524288,
  total_physical_size: 84758848,
  total_available_size: 2217024,
  used_heap_size: 82159392,
  heap_size_limit: 16777216,
  malloced_memory: 16384,
  peak_malloced_memory: 418144,
  does_zap_garbage: 0,
  number_of_native_contexts: 1,
  number_of_detached_contexts: 0
}

How is this possible?

Note: I've also tried running with --max-old-space-size with similar results.

0 Answers
Related