<small id='1KM44'></small><noframes id='1KM44'>

    <bdo id='1KM44'></bdo><ul id='1KM44'></ul>

      <i id='1KM44'><tr id='1KM44'><dt id='1KM44'><q id='1KM44'><span id='1KM44'><b id='1KM44'><form id='1KM44'><ins id='1KM44'></ins><ul id='1KM44'></ul><sub id='1KM44'></sub></form><legend id='1KM44'></legend><bdo id='1KM44'><pre id='1KM44'><center id='1KM44'></center></pre></bdo></b><th id='1KM44'></th></span></q></dt></tr></i><div id='1KM44'><tfoot id='1KM44'></tfoot><dl id='1KM44'><fieldset id='1KM44'></fieldset></dl></div>
      <legend id='1KM44'><style id='1KM44'><dir id='1KM44'><q id='1KM44'></q></dir></style></legend>
    1. <tfoot id='1KM44'></tfoot>

    2. requestAnimationFrame 垃圾回收

      时间:2023-10-12

      • <bdo id='338GS'></bdo><ul id='338GS'></ul>
        <i id='338GS'><tr id='338GS'><dt id='338GS'><q id='338GS'><span id='338GS'><b id='338GS'><form id='338GS'><ins id='338GS'></ins><ul id='338GS'></ul><sub id='338GS'></sub></form><legend id='338GS'></legend><bdo id='338GS'><pre id='338GS'><center id='338GS'></center></pre></bdo></b><th id='338GS'></th></span></q></dt></tr></i><div id='338GS'><tfoot id='338GS'></tfoot><dl id='338GS'><fieldset id='338GS'></fieldset></dl></div>

        1. <small id='338GS'></small><noframes id='338GS'>

            <legend id='338GS'><style id='338GS'><dir id='338GS'><q id='338GS'></q></dir></style></legend>

              <tbody id='338GS'></tbody>
              • <tfoot id='338GS'></tfoot>
              • 本文介绍了requestAnimationFrame 垃圾回收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                I'm profiling the following code's memory usage using the Timeline in Chrome Dev Tools v27.

                <!DOCTYPE html>
                <html>
                <head>
                  <meta http-equiv='content-type' content='text/html; charset=UTF-8' />
                  <title>RAF</title>
                </head>
                  <body>
                    <script type='text/javascript' charset='utf-8'>
                      var frame = function() {
                        window.webkitRequestAnimationFrame(frame);
                      };
                      window.webkitRequestAnimationFrame(frame);
                    </script>
                  </body>
                </html>
                

                Notice it's simple. But eventually I see the a tooth pattern appear that indicates the garbage collector is reclaiming memory.

                Does raf create garbage objects by default? Is there any way to avoid this? Thx.

                解决方案

                I have found out the following: If you change your RAF function into two "ping-pong" like functions, you get alot less garbage. You can't avoid the first initial "big GC", but after that you see only minor GCs of about 50kb instead of 700kb-1mb GCs. The code will look like this:

                <script type='text/javascript' charset='utf-8'>
                  window.frameA = function() {
                    window.webkitRequestAnimationFrame(window.frameB);
                  };
                  window.frameB = function() {
                    window.webkitRequestAnimationFrame(window.frameA);
                  };
                  window.webkitRequestAnimationFrame(window.frameA);
                </script>
                

                I guess this is the best you can do in Chrome. I noticed that in FF the gc intervals or memory hardly changes, so its probably related to the chrome debugging stuff (see the linked chrome bug report above for more details). However, I noticed an improvement in my own game when deploying RAF like this - and heck I need to be able to debug it without artificial GCs that won't happen on normal users machines.

                这篇关于requestAnimationFrame 垃圾回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:将对象设置为 null 时的 JavaScript(ES6)WeakMap 垃圾回 下一篇:将对象的所有键转换为小写的最佳方法(最有效

                相关文章

                最新文章

                <small id='HxLsX'></small><noframes id='HxLsX'>

                  <bdo id='HxLsX'></bdo><ul id='HxLsX'></ul>

                  <legend id='HxLsX'><style id='HxLsX'><dir id='HxLsX'><q id='HxLsX'></q></dir></style></legend>
                    <tfoot id='HxLsX'></tfoot>
                    <i id='HxLsX'><tr id='HxLsX'><dt id='HxLsX'><q id='HxLsX'><span id='HxLsX'><b id='HxLsX'><form id='HxLsX'><ins id='HxLsX'></ins><ul id='HxLsX'></ul><sub id='HxLsX'></sub></form><legend id='HxLsX'></legend><bdo id='HxLsX'><pre id='HxLsX'><center id='HxLsX'></center></pre></bdo></b><th id='HxLsX'></th></span></q></dt></tr></i><div id='HxLsX'><tfoot id='HxLsX'></tfoot><dl id='HxLsX'><fieldset id='HxLsX'></fieldset></dl></div>