Is there a limit on the number of members in a Javascript Set()? Or is this a bug in V8

≡放荡痞女 提交于 2019-12-24 01:19:45

问题


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?

来源:https://stackoverflow.com/questions/34971500/is-there-a-limit-on-the-number-of-members-in-a-javascript-set-or-is-this-a-bu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!