JS 内存泄漏

<!DOCTYPE HTML>
<html>
<body>

Makes XHR request every 50ms. Watch the memory. Fixes XHR leak in older IEs.

<script>
onload = function() {
  setInterval(function(){
     var xhr = new XMLHttpRequest()
     xhr.open('GET', 'jquery.js', true)
     xhr.onreadystatechange = function() {
        if(this.readyState == 4 && this.status == 200) {            
           document.getElementById('test').innerHTML++
        }
     }
     xhr.send(null)
     xhr = null
  }, 50)
}
</script>
<div id="test">0</div>

</body>
</html>
原文地址:https://www.cnblogs.com/ok519/p/2871285.html