内存泄漏的原因

时间:2017-01-17 19:44:54

标签: javascript memory

为什么这段代码会导致内存泄漏?

    <html>
    <body>
    <script type="text/javascript">
    document.write("Program to illustrate memory leak via closure");
    window.onload=function outerFunction(){
        var obj = document.getElementById("element");
        obj.onclick=function innerFunction(){
        alert("Hi! I will leak");
        };
        obj.bigString=new Array(1000).join(new Array(2000).join("XXXXX"));
        // This is used to make the leak significant
    };
    </script>
    <button id="element">Click Me</button>
    </body>
    </html>

它从这里列出5 http://www.ibm.com/developerworks/web/library/wa-memleak/

1 个答案:

答案 0 :(得分:0)

看起来像现代浏览器捕获这些泄漏,在4清单中解释,需要阅读完整的文章