我花了最后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;
我的monolog配置:
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]
有任何纠正此事的建议吗?
答案 0 :(得分:6)
找到解决方案。我不能告诉你这种内存泄漏发生的确切原因,但是根据this的说法;在命令中添加--no-debug
选项可以解决问题。它实际上做了,它甚至减少了2mb的内存。干杯!
答案 1 :(得分:0)
有趣的是,当我添加该选项时,内存使用量实际上翻倍。调用垃圾收集似乎也无法解决这个问题。
答案 2 :(得分:0)
除了@delmalki的答案外,您可能还想检查是否有任何fingers_crossed
处理函数并设置buffer_size
:
monolog:
handlers:
main:
type: fingers_crossed
action_level: critical
handler: grouped
excluded_404s:
- ^
buffer_size: 30