Background
I was getting FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
It was happening around 512 mb
Scavenge (reduce) 507.8 (518.9) -> 507.2 (518.9) MB, 2.4 / 0.0 ms
I believe a heap out of memory error should happen at 1024mb, not 512mb, because I'm running my program on a heroku dyno with 1gb (1024mb).
I made some changes to my app to try to fix this.
Question
I want recreate a situation where over 512mb of ram are used up. This way I can see if my changes fixed the problem. Or if my app still crashes.
How would one go about this?
I Tried
I tried creating a route that adds 1000mb buffers to a global array. But this took the heap used down by about 1mb. I would think it would take 3000mb out of the heap on each request. But maybe those buffers aren't store in the heap?
const crashArray =[];
someRoute.get('/', async (req, res, next) => {
console.log(process.memoryUsage().heapUsed);
// returns> 52848344
const a = Buffer.alloc(1000000000);
const b = Buffer.alloc(1000000000);
const c = Buffer.alloc(1000000000);
crashArray.push(a);
console.log('after adding buffer to arrays' + process.memoryUsage().heapUsed);
// returns> 51684512
res.send(200);
});