内存泄漏symfony和独白和控制台

Memory leak symfony and monolog and console

我花了最后 2 个小时试图找到我的内存泄漏。

结果是

例子

 # this leaks
 # start mem: 28 mb end mem: 38mb, n = 5k
 foreach ($this->queryData->iterate() as $j => $data):
            declare(ticks = 1);
            self::$currentAd++;
            $this->em->detach($data[0]);
            $this->logger->info(LogUtility::getMemoryUsage() . " (" . self::$currentAd .")");
            if(self::$currentAd === 40000 ):
                break(2);
            endif;
  endforeach;

 # this doesn't leak
 # start mem: 28 mb end mem: 30mb, n = 40k
 foreach ($this->queryData->iterate() as $j => $data):
            declare(ticks = 1);
            self::$currentAd++;
            $this->em->detach($data[0]);
            if(self::$currentAd % 50 == 0):
                  $this->logger->info(LogUtility::getMemoryUsage() . " (" . self::$currentAd .")");
            endif;
            if(self::$currentAd === 40000 ):
                break(2);
            endif;
  endforeach;

我的独白配置:

 handlers:
    test:
        type:   stream
        path:   "%kernel.logs_dir%/immobilier/test.log"
        level:  debug
        channels: test
  console:
        type:   console
        bubble: false
        verbosity_levels:
            VERBOSITY_VERBOSE: INFO
            VERBOSITY_VERY_VERBOSE: DEBUG
        channels: [test]

有任何纠正此问题的建议吗?

找到解决方案。我不能告诉你发生这种内存泄漏的确切原因,但是根据 this;在命令中添加 --no-debug 选项可以解决问题。它确实做到了,甚至减少了 2mb 的内存。干杯!

除了@delmalki 的回答之外,您可能还想检查是否有任何 fingers_crossed 处理程序并设置 buffer_size:

monolog:
    handlers:
        main:
            type: fingers_crossed
            action_level: critical
            handler: grouped
            excluded_404s:
                - ^
            buffer_size: 30