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

    1. <tfoot id='ufyPW'></tfoot>

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

        如何请求 node.js 中的垃圾收集器运行?

        时间:2023-10-12
            <i id='lC2ae'><tr id='lC2ae'><dt id='lC2ae'><q id='lC2ae'><span id='lC2ae'><b id='lC2ae'><form id='lC2ae'><ins id='lC2ae'></ins><ul id='lC2ae'></ul><sub id='lC2ae'></sub></form><legend id='lC2ae'></legend><bdo id='lC2ae'><pre id='lC2ae'><center id='lC2ae'></center></pre></bdo></b><th id='lC2ae'></th></span></q></dt></tr></i><div id='lC2ae'><tfoot id='lC2ae'></tfoot><dl id='lC2ae'><fieldset id='lC2ae'></fieldset></dl></div>
          1. <legend id='lC2ae'><style id='lC2ae'><dir id='lC2ae'><q id='lC2ae'></q></dir></style></legend>

              <tfoot id='lC2ae'></tfoot>

            1. <small id='lC2ae'></small><noframes id='lC2ae'>

                <tbody id='lC2ae'></tbody>
                  <bdo id='lC2ae'></bdo><ul id='lC2ae'></ul>
                • 本文介绍了如何请求 node.js 中的垃圾收集器运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在启动时,我的 node.js 应用似乎使用了大约 200MB 的内存.如果我不理会它一段时间,它会缩小到 9MB 左右.

                  At startup, it seems my node.js app uses around 200MB of memory. If I leave it alone for a while, it shrinks to around 9MB.

                  是否可以在应用内:

                  1. 检查应用使用了多少内存?
                  2. 请求垃圾收集器运行?

                  我问的原因是,我从磁盘加载了一些文件,这些文件是临时处理的.这可能会导致内存使用量激增.但是我不想在 GC 运行之前加载更多文件,否则会有内存不足的风险.

                  The reason I ask is, I load a number of files from disk, which are processed temporarily. This probably causes the memory usage to spike. But I don't want to load more files until the GC runs, otherwise there is the risk that I will run out of memory.

                  有什么建议吗?

                  推荐答案

                  如果使用 --expose-gc 标志启动节点进程,则可以调用 global.gc() 强制节点运行垃圾回收.请记住,节点应用程序中的所有其他执行都会暂停,直到 GC 完成,所以不要太频繁地使用它,否则会影响性能.

                  If you launch the node process with the --expose-gc flag, you can then call global.gc() to force node to run garbage collection. Keep in mind that all other execution within your node app is paused until GC completes, so don't use it too often or it will affect performance.

                  您可能希望在从代码中进行 GC 调用时包含一个检查,这样如果节点在没有标志的情况下运行,事情就不会变坏:

                  You might want to include a check when making GC calls from within your code so things don't go bad if node was run without the flag:

                  try {
                    if (global.gc) {global.gc();}
                  } catch (e) {
                    console.log("`node --expose-gc index.js`");
                    process.exit();
                  }
                  

                  这篇关于如何请求 node.js 中的垃圾收集器运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:JavaScript 闭包是如何被垃圾回收的 下一篇:在 Google Chrome 中强制进行垃圾收集

                  相关文章

                  最新文章

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

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