• <legend id='0qgqq'><style id='0qgqq'><dir id='0qgqq'><q id='0qgqq'></q></dir></style></legend>
      • <bdo id='0qgqq'></bdo><ul id='0qgqq'></ul>

        <small id='0qgqq'></small><noframes id='0qgqq'>

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

        <tfoot id='0qgqq'></tfoot>

        诊断内存泄漏 - 已用完 # 字节的允许内存大小

        时间:2023-07-16

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

                <tbody id='HoXXZ'></tbody>

            • <small id='HoXXZ'></small><noframes id='HoXXZ'>

                • <bdo id='HoXXZ'></bdo><ul id='HoXXZ'></ul>
                  <tfoot id='HoXXZ'></tfoot>
                • <legend id='HoXXZ'><style id='HoXXZ'><dir id='HoXXZ'><q id='HoXXZ'></q></dir></style></legend>
                • 本文介绍了诊断内存泄漏 - 已用完 # 字节的允许内存大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我遇到了可怕的错误消息,可能是经过艰苦的努力,PHP 内存不足:

                  I've encountered the dreaded error-message, possibly through-painstaking effort, PHP has run out of memory:

                  第 123 行的 file.php 中 #### 字节的允许内存大小耗尽(尝试分配 #### 字节)

                  Allowed memory size of #### bytes exhausted (tried to allocate #### bytes) in file.php on line 123

                  增加限制

                  如果您知道自己在做什么并想增加限制,请参阅memory_limit:

                  ini_set('memory_limit', '16M');
                  ini_set('memory_limit', -1); // no limit
                  

                  当心!您可能只是在解决症状,而不是问题!

                  Beware! You may only be solving the symptom and not the problem!

                  错误消息指向我认为正在泄漏或不必要地累积内存的带有循环的行.我在每次迭代结束时打印了 memory_get_usage() 语句,可以看到数字缓慢增长直到达到限制:

                  The error message points to a line withing a loop that I believe to be leaking, or needlessly-accumulating, memory. I've printed memory_get_usage() statements at the end of each iteration and can see the number slowly grow until it reaches the limit:

                  foreach ($users as $user) {
                      $task = new Task;
                      $task->run($user);
                      unset($task); // Free the variable in an attempt to recover memory
                      print memory_get_usage(true); // increases over time
                  }
                  

                  出于这个问题的目的,让我们假设可以想象的最糟糕的意大利面条式代码隐藏在全局范围内的$userTask 中.

                  For the purposes of this question let's assume the worst spaghetti code imaginable is hiding in global-scope somewhere in $user or Task.

                  哪些工具、PHP 技巧或调试伏都教可以帮助我找到并解决问题?

                  推荐答案

                  PHP 没有垃圾收集器.它使用引用计数来管理内存.因此,最常见的内存泄漏源是循环引用和全局变量.如果您使用一个框架,恐怕您将有很多代码需要搜索才能找到它.最简单的方法是有选择地调用 memory_get_usage 并将其缩小到代码泄漏的位置.您还可以使用 xdebug 来创建代码跟踪.使用 执行跟踪 和 show_mem_delta 运行代码.

                  PHP doesn't have a garbage collector. It uses reference counting to manage memory. Thus, the most common source of memory leaks are cyclic references and global variables. If you use a framework, you'll have a lot of code to trawl through to find it, I'm afraid. The simplest instrument is to selectively place calls to memory_get_usage and narrow it down to where the code leaks. You can also use xdebug to create a trace of the code. Run the code with execution traces and show_mem_delta.

                  这篇关于诊断内存泄漏 - 已用完 # 字节的允许内存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Google BigQuery API PHP 凭证 下一篇:php/symfony/doctrine 内存泄漏?

                  相关文章

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

                  1. <legend id='XMk9q'><style id='XMk9q'><dir id='XMk9q'><q id='XMk9q'></q></dir></style></legend>

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

                      <tfoot id='XMk9q'></tfoot>
                        <bdo id='XMk9q'></bdo><ul id='XMk9q'></ul>