I am working on a system designed to keep processes behaving properly and I need to test its memory usage kill switch. I am yet to find a way to quickly and efficiently use alot of system memory quickly with node.js. I have tried using arrays but it seems as if the garbage collector compresses them. Basically, I need to deliberately cause a fast memory leak.
EDIT: I need to reach around 4 gigabytes of used system memory by one process.
If garbage collector is compressing your array, maybe you are pushing always the same value inside it.
you should try shomething like
var a =  for (let i = 0; i < 9000000000; i++)
You also should run your process with a flag to increase memory limit. Note that with a limit of 9Mld, your array will be bigger then 4GB and your process will exit with non zero status code.
node –max_old_space_size=4096 yourscript.js