Created
December 5, 2009 19:37
-
-
Save aarongustafson/249828 to your computer and use it in GitHub Desktop.
Example of a memory leak issue in IE and how to resolve it
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
window.onload = function() | |
{ | |
var | |
body = document.getElementsByTagName('body')[0], | |
div = document.createElement('div'), | |
parentDiv, childDiv; | |
for ( i = 0; i < 5000; i++ ) | |
{ | |
parentDiv = div.cloneNode(true); | |
parentDiv.onclick = foo; | |
childDiv = div.cloneNode(true); | |
childDiv.onclick = bar; | |
// Doesn't Leak | |
body.appendChild(parentDiv); | |
parentDiv.appendChild(childDiv); | |
body.removeChild(parentDiv); | |
parentDiv.removeChild(childDiv); | |
parentDiv = null; | |
childDiv = null; | |
} | |
body = null; | |
} |
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
window.onload = function() | |
{ | |
var | |
body = document.getElementsByTagName('body')[0], | |
div = document.createElement('div'), | |
parentDiv, childDiv; | |
for ( i = 0; i < 5000; i++ ) | |
{ | |
parentDiv = div.cloneNode(true); | |
parentDiv.onclick = foo; | |
childDiv = div.cloneNode(true); | |
childDiv.onclick = bar; | |
// Leaks | |
parentDiv.appendChild(childDiv); | |
body.appendChild(parentDiv); | |
body.removeChild(parentDiv); | |
parentDiv.removeChild(childDiv); | |
parentDiv = null; | |
childDiv = null; | |
} | |
body = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment