<html><body> <script type="text/javascript"> document.write("Avoiding memory leak via closure by breaking the circular reference"); window.onload = function outerFunction() { var obj = document.getElementById("element") obj.onclick = function innerFunction() { alert("Hi! I have avoided the leak"); // Some logic here } obj.bigString = new Array(1000).join(new Array(1000).join("XXXXX")) obj = null //This breaks the circular reference } </script> <button id="element">Click Me</button></body></html>在 https://www.ibm.com/developer... 這篇IBM 關(guān)于JS內(nèi)存泄漏的文章中,提到 DOM 與 JS 對象 obj 存在循環(huán)引用。為什么這兩者存在相互引用呢?另外,文中也提到解決方法:obj = null 打破循環(huán)引用。為什么我在 Chrome 的 Profile 中,無論 obj = null 是否存在這句,內(nèi)存占用量是相等的,是否說明這句無效,依然存在內(nèi)存泄漏呢?
Js 內(nèi)存泄漏問題
炎炎設(shè)計
2018-10-19 18:15:01