Created
August 15, 2014 03:33
-
-
Save anonymous/9e2f4edc0861a6011dcd to your computer and use it in GitHub Desktop.
// source http://jsbin.com/fafarujewozu/1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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