Created
April 19, 2012 07:48
-
-
Save jbt/2419469 to your computer and use it in GitHub Desktop.
jQuery jsonp auto-generated callbacks memory leak.
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
<?php | |
// Only run this locally, unless you want to bombard your server with hundreds of requests a second. | |
if($_GET['a']) die( $_GET['callback'] . '(false);'); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>JSONP Memory leak test</title> | |
<script type='text/javascript' src='http://code.jquery.com/jquery-git.js'></script> | |
</head> | |
<body> | |
<div id="a"></div> | |
<button onclick="start();">Start</button> | |
<button onclick="stop();">Stop</button> | |
<script type="text/javascript"> | |
var i = 0, interval, pingTo = window.location + '?a=1&callback=?'; | |
function cb(){ | |
document.getElementById('a').innerHTML = i++; | |
} | |
function ping(){ | |
var j = 10; | |
while(j--) | |
$.ajax(pingTo, { | |
crossDomain: true, | |
dataType: 'jsonp', | |
success: cb | |
}); | |
} | |
function start(){ | |
interval = setInterval(ping, 10); | |
} | |
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