secret
Last active — forked from getify/gist:a73c0f06a46962500dc8

memory leak experiments

  • Download Gist
leak.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Leak Test</title>
<meta http-equiv="refresh" content="2;url=">
</head>
<body>
<script type="text/javascript">
// http://gyazo.com/330b6b2f7809db8a12549b523db8efc0.png
(function() {
var data = { };
var i =-1, l = 1000;
while (++i < l) {
(function(i) {
data[i] = new ActiveXObject('Microsoft.XMLHTTP');
data[i].onreadystatechange = function(){
if (data[i].readyState == 4) {
alert(data[i].responseText);
}
};
})(i);
}
})();
</script>
</body>
</html>
noleak.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>No Leak Test</title>
<meta http-equiv="refresh" content="2;url=">
</head>
<body>
<script type="text/javascript">
// http://gyazo.com/6b30dbf5ff1c49c6466691a942c4a757.png
// moved `data` to the global namespace
var data = { };
 
(function() {
var i =-1, l = 1000;
while (++i < l) {
(function(i) {
data[i] = new ActiveXObject('Microsoft.XMLHTTP');
data[i].onreadystatechange = function(){
if (data[i].readyState == 4) {
alert(data[i].responseText);
}
};
})(i);
}
})();
</script>
</body>
</html>
noleak_too.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>No Leak Test</title>
<meta http-equiv="refresh" content="2;url=">
</head>
<body>
<script type="text/javascript">
(function(global) {
// this will work too
global.data = { };
 
var i =-1, l = 1000;
while (++i < l) {
(function(i) {
data[i] = new ActiveXObject('Microsoft.XMLHTTP');
data[i].onreadystatechange = function(){
if (data[i].readyState == 4) {
alert(data[i].responseText);
}
};
})(i);
}
})(this);
</script>
</body>
</html>
noleak_too_jdd.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>No Leak Test</title>
<meta http-equiv="refresh" content="2;url=">
</head>
<body>
<script type="text/javascript">
// this will do too :D
var data = { },
 
createHandler = function(id) {
return function() {
var xhr = data[id];
if (xhr.readyState == 4) {
alert(xhr.responseText);
}
};
},
 
getId = (function() {
var id = 0;
return function() {
return ++id;
};
})(),
 
Ajaxy = function() {
this.id = getId();
this.raw =
data[this.id] = new ActiveXObject('Microsoft.XMLHTTP');
this.raw.onreadystatechange = createHandler(this.id);
};
 
(function() {
var i =-1, l = 1000;
while (++i < l) new Ajaxy;
})();
</script>
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.