Skip to content

Instantly share code, notes, and snippets.

Created August 15, 2014 03:33
Show Gist options
  • Select an option

  • Save anonymous/9e2f4edc0861a6011dcd to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/9e2f4edc0861a6011dcd to your computer and use it in GitHub Desktop.
<html>
<body>
<script type="text/javascript">
document.write("Program to illustrate memory leak via closure");
window.onload = function outerFunction() {
// obj 中存放了 dom#element 的引用
var obj = document.getElementById("element");
// obj 引用的 dom#element 被赋值 (循环引用是在这里被引入的????)
obj.onclick = function innerFunction(){
alert("Hi! I will leak");
};
// obj 引用的 dom#element 被赋值 从而有了到
obj.bigString = new Array(1).join(new Array(1).join("XXXXX"));
};
</script>
<button id="element">Click Me</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment