我有一个分配数组的简单Node方法:
function allocateArray(size) {
let arr = Array(size).fill('Hello World');
console.log(`Array size: ${arr.length}`);
console.log(v8.getHeapStatistics());
console.log();
}
allocateArray(1e7);
当我使用命令node --max-heap-size=16 test.js
运行脚本时,会显示以下堆统计信息,看来使用的堆大小远大于堆大小限制:
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
}
这怎么可能?
注意:我还尝试过在
--max-old-space-size
上运行,但结果相似。