开发者

Changing location hash, onhashchange and memory leaks

开发者 https://www.devze.com 2023-03-28 14:01 出处:网络
When running the following script in Safari and Firefox 5 (other browsers not tested), the memory usage of both browsers increase drastically. But after the 开发者_如何学Pythonfunction finished, the m

When running the following script in Safari and Firefox 5 (other browsers not tested), the memory usage of both browsers increase drastically. But after the 开发者_如何学Pythonfunction finished, the memory usage still keeps being very high. Safaris memory usage grows by ~80MB, FF up to 200MB.

Any thoughts why, even after some minutes, the memory usage does not decrease?

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <script type="text/javascript">
      window.onhashchange = function() {
        var i = 1; // do something
      };

      function leakIt() {
        for(var i = 0; i < 10000; i++) {
          window.location.hash = i%4; // Trigger onhashchange
        }
      };

      window.onload = function() {
        document.getElementById('leak').addEventListener('click', leakIt,false);
      };
    </script>
  </head>
  <body>
    <button id="leak">Leak it!</button>
  </body>
</html>

Additional information

If I reload the page in Safari and call the leakIt function again, the memory increases by about 20MB and after leakIt terminates, the memory usage goes back to the amount after the first call to leakIt.


What happend when you refresh the page? While you keep refreshing page and the memory keep increasing,That is memory leak.You can use Sieve to detect that.

0

精彩评论

暂无评论...
验证码 换一张
取 消