How do I create a memory leak in JavaScript?

前端 未结 6 1714
南笙
南笙 2021-01-31 03:34

I would like to understand what kind of code causes memory leaks in JavaScript and created the script below. However, when I run the script in Safari 6.0.4 on OS X the memory co

6条回答
  •  半阙折子戏
    2021-01-31 04:19

    I tried to do something like that and got exception out of memory.

    const test = (array) => {
      array.push((new Array(1000000)).fill('test'));
    };
    
    const testArray = [];
    
    for(let i = 0; i <= 1000; i++) {
      test(testArray);
    }
    

提交回复
热议问题