Why doesn't Buffer.alloc() affect the javascript heap in node.js?

Viewed 18

I created three 1000mb buffers and pushed to an array. But this took the heapUsed down by about 2mb. I would think it would take 3000mb out of the heap.

Why doesn't the buffer affect the heap?

const crashArray =[];

console.log(process.memoryUsage().heapUsed);
// returns> 53064248    

const a = Buffer.alloc(1000000000);
const b = Buffer.alloc(1000000000);
const c = Buffer.alloc(1000000000);
crashArray.push(a);
crashArray.push(b);
crashArray.push(c);

console.log('after adding buffer to arrays' + process.memoryUsage().heapUsed);
// returns> 51725480    
0 Answers
Related