<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 中泄漏内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))
                can#39;t get response status code with JavaScript fetch(无法使用 JavaScript 获取响应状态代码)
                • <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'>