How do you detect memory limits in JavaScript?

后端 未结 3 2215
梦谈多话
梦谈多话 2020-12-02 11:23

Can browsers enforce any sort of limit on the amount of data that can be stored in JavaScript objects? If so, is there any way to detect that limit?

It appears that

3条回答
  •  眼角桃花
    2020-12-02 11:39

    In Chrome the answer is Sure!

    Go to the console and type:

    performance.memory.jsHeapSizeLimit; // will give you the JS heap size
    performance.memory.usedJSHeapSize; // how much you're currently using
    
    arr = []; for(var i = 0; i < 100000; i++) arr.push(i);
    performance.memory.usedJSHeapSize; // likely a larger number now
    

提交回复
热议问题