letarr=["a single pickle"]leti=1while(true){arr=[arr]console.log(i++,JSON.stringify(arr).length,arr.flat(Infinity))}
This reliably gives out at
3910 7839 [ 'a single pickle' ]
/scrap.js:5
console.log(i++, JSON.stringify(arr).length, arr.flat(Infinity))
^
RangeError: Maximum call stack size exceeded
at JSON.stringify (<anonymous>)
Without the stringify though?
constlen=128letarr=["a single pickle"]leti=0while(i<74624){for(leti=0;i<len;i++)arr=[arr]console.log((i+=len),arr.flat(Infinity))}while(true){arr=[arr]console.log(++i,arr.flat(Infinity))}
74776 [ 'a single pickle' ]
Segmentation fault (core dumped)
But what is the most nested array we can make at all?
constlen=128letarr=["a single pickle"]leti=0while(true){for(leti=0;i<len;i++)arr=[arr]console.log((i+=len))}
Ambitious much?
So, I had to find out.
This reliably gives out at
Without the
stringify
though?But what is the most nested array we can make at all?
Just runs out of default memory limit
The second issue (segfault) was fixed a few weeks back…the rest is working as intended
Just tried the segfaulting example on
node v11.10.0
on Windows.And it just quits (very early) with no error? :/
And then nothing.
The fix Hemanth mentioned is in V8. It will become available in Node.js once they update their V8 dependency.