Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how much memory does node allocate for null values in arrays

Following up on this thread:

Lots of null values in an array mean any harm?

I did this with node.js:

arr=[]
arr[1000]=1
arr[1000000000]=2
arr.sort()

And I got

FATAL ERROR: JS Allocation failed - process out of memory

So that leaves me with the question (I couldn't find it on Yahoogle) how much memory is actually allocated for a null entry in an array in node. I do not plan to use 1000000000 entries, not even close, but maybe it's still not worth allocating the memory...

Who knows how I can check?

like image 932
EasierSaidThanDone Avatar asked Jun 30 '12 20:06

EasierSaidThanDone


1 Answers

So in summary, node.js does not allocate memory for undefined values in an array. The crash I experienced must have been a glitch as no one else could reproduce it and installing the latest node.js version eliminated the problem for me as well.

like image 105
EasierSaidThanDone Avatar answered Nov 02 '22 22:11

EasierSaidThanDone