Is there a limit on the number of members in a Jav

2019-07-11 18:17发布

Here's some simple Javascript code that repeatedly adds integers into a Set:

var i;
var limit = 1 << 24;
var s = new Set();

for (i = 0; i < limit + 10; i++) {
    s.add(i);
    if (i >= limit - 10) console.log ("Set size is now " + s.size)
}

When the set size grows to 2^24 exactly (which I've called "limit"), there is a

FATAL ERROR: invalid table size Allocation failed - process out of memory

The process isn't anywhere near running into an actual memory limit, and it's really suspicious that this occurs at exactly 2^24 elements. This happens using node.js, or if I run it inside Chrome. I've tried it on both Windows and Mac OSX (both 64 bit), and it seems to hit the wall at 2^24 elements when you store other more complex things in Set()s. I think Map() and its ilk all have the same issue.

I couldn't find anything about this limit in the documentation. Is it a bug?

0条回答
登录 后发表回答