Skip to content

Instantly share code, notes, and snippets.

@hushicai
Last active June 2, 2016 05:30
Show Gist options
  • Save hushicai/11315775 to your computer and use it in GitHub Desktop.
Save hushicai/11315775 to your computer and use it in GitHub Desktop.
jsonp memory leak test
<!DOCTYPE html>
<html>
<head>
<title>jsonp-memory-leak</title>
<meta charset="utf-8" />
</head>
<body>
<script>
function x(data) {
// console.log(data);
}
function loaded() {
this.parentNode.removeChild(this);
this.onload = null;
}
var interval;
function start() {
var script = document.createElement('script');
var id = script.id = 'script_' + (+new Date).toString(36);
script.src = 'http://localhost:3000?callback=x';
script.onload = loaded;
document.head.appendChild(script);
// cycle
//document.getElementById(id).expando = script;
//script.bigString = new Array(1000).join('xxx');
}
function loop() {
interval = setInterval(start, 100);
}
function stop() {
clearInterval(interval);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment