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?

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.

EDIT : Sorry for inexact, Might not be applicable to JAVA..
Still might be helpful for someone who need it in other application.

An Array of reference is allocating x

therefore allocating arr[100000] will allocate 100 kb x 4b ~= 0.5Mb (approximating)

and YES, definitely, if you ain't gonna use all the Array,
you should consider a HashMap which is a datastructure just for that..
HashMap is best in having a large search span with relative small amount of items.

Either way, there are solutions to allocate a small array, and expand it as needed, if needed.