<legend id='Ka9nv'><style id='Ka9nv'><dir id='Ka9nv'><q id='Ka9nv'></q></dir></style></legend>
  1. <small id='Ka9nv'></small><noframes id='Ka9nv'>

  2. <i id='Ka9nv'><tr id='Ka9nv'><dt id='Ka9nv'><q id='Ka9nv'><span id='Ka9nv'><b id='Ka9nv'><form id='Ka9nv'><ins id='Ka9nv'></ins><ul id='Ka9nv'></ul><sub id='Ka9nv'></sub></form><legend id='Ka9nv'></legend><bdo id='Ka9nv'><pre id='Ka9nv'><center id='Ka9nv'></center></pre></bdo></b><th id='Ka9nv'></th></span></q></dt></tr></i><div id='Ka9nv'><tfoot id='Ka9nv'></tfoot><dl id='Ka9nv'><fieldset id='Ka9nv'></fieldset></dl></div>
      <bdo id='Ka9nv'></bdo><ul id='Ka9nv'></ul>
    1. <tfoot id='Ka9nv'></tfoot>
    2. Fetch API 在 Chrome 中泄漏内存

      Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)

            <tbody id='M5bCq'></tbody>

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

          • <tfoot id='M5bCq'></tfoot>
            • <legend id='M5bCq'><style id='M5bCq'><dir id='M5bCq'><q id='M5bCq'></q></dir></style></legend>

              <i id='M5bCq'><tr id='M5bCq'><dt id='M5bCq'><q id='M5bCq'><span id='M5bCq'><b id='M5bCq'><form id='M5bCq'><ins id='M5bCq'></ins><ul id='M5bCq'></ul><sub id='M5bCq'></sub></form><legend id='M5bCq'></legend><bdo id='M5bCq'><pre id='M5bCq'><center id='M5bCq'></center></pre></bdo></b><th id='M5bCq'></th></span></q></dt></tr></i><div id='M5bCq'><tfoot id='M5bCq'></tfoot><dl id='M5bCq'><fieldset id='M5bCq'></fieldset></dl></div>
                <bdo id='M5bCq'></bdo><ul id='M5bCq'></ul>
              • 本文介绍了Fetch API 在 Chrome 中泄漏内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                以最简单的方式使用 fetch-API 时,Chrome 无法正确进行垃圾收集.我做错了吗?

                When using the fetch-API in the most simple way, Chrome is not garbage collecting correctly. Am I doing something wrong?

                for (i = 0; i < 100; i++) {
                  fetch('https://upload.wikimedia.org/wikipedia/commons/3/3d/LARGE_elevation.jpg')
                    .then(response => {
                      console.log('Memory-bloating')
                    })
                }
                

                https://jsfiddle.net/dozrpcvj/12/

                这个 JSFiddle 用 1.4GB 填充内存,直到您手动进行垃圾收集或关闭选项卡后才会释放.如果将迭代次数增加到 1000 次,它会下载"14GB(从自己的磁盘),而不是垃圾收集,而是开始填充磁盘上的交换文件.

                This JSFiddle fills the memory with 1.4GB, which doesn't release until you either manually garbage collect or you close the tab. If you increase the number of iterations to 1000 it "downloads" 14GB (from the own disk) and instead of garbage collecting it starts filling the swap file on disk.

                是我做错了什么还是 Chrome 中的错误?使用 Safari 进行测试时,它也会用 1.4GB 填充硬盘驱动器,但一旦完成就会开始垃圾收集.

                Am I doing something wrong or is this a bug in Chrome? When testing with Safari, it also fills the hard drive with 1.4GB, but starts garbage collecting as soon as it's done.

                PS.您不能使用内存分析器,因为它告诉您只使用几 MB 的数据,即使活动监视器或 Chrome 自己的任务管理器显示 1.4GB.

                PS. You can't use the memory profiler, since that tells you that you only use a few MB of data, even if the Activity Monitor or Chromes own Task Manager says 1.4GB.

                推荐答案

                你没有做错;只是当你同时调用一堆 Promise 时,会占用大量内存.如果你想确保它不使用太多内存——并且你愿意让它花更长的时间——你可以把它全部放在一个异步函数中并这样做:

                You're doing nothing wrong; it's just that when you call a bunch of promises at the same time, that's going to use a lot of memory. If you want to make sure that it doesn't use as much memory--and you're willing to have it take longer--you could put this all inside of an async function and do this:

                for (i = 0; i < 100; i++) {
                  await fetch('https://upload.wikimedia.org/wikipedia/commons/3/3d/LARGE_elevation.jpg')
                  console.log('Memory-bloating')
                }
                

                这篇关于Fetch API 在 Chrome 中泄漏内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                • <i id='Y2tt4'><tr id='Y2tt4'><dt id='Y2tt4'><q id='Y2tt4'><span id='Y2tt4'><b id='Y2tt4'><form id='Y2tt4'><ins id='Y2tt4'></ins><ul id='Y2tt4'></ul><sub id='Y2tt4'></sub></form><legend id='Y2tt4'></legend><bdo id='Y2tt4'><pre id='Y2tt4'><center id='Y2tt4'></center></pre></bdo></b><th id='Y2tt4'></th></span></q></dt></tr></i><div id='Y2tt4'><tfoot id='Y2tt4'></tfoot><dl id='Y2tt4'><fieldset id='Y2tt4'></fieldset></dl></div>
                    <tbody id='Y2tt4'></tbody>

                    <bdo id='Y2tt4'></bdo><ul id='Y2tt4'></ul>
                    <legend id='Y2tt4'><style id='Y2tt4'><dir id='Y2tt4'><q id='Y2tt4'></q></dir></style></legend>
                          <tfoot id='Y2tt4'></tfoot>

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