Memory leak when executing Doctrine query in loop

后端 未结 6 1744
梦毁少年i
梦毁少年i 2020-12-31 07:32

I\'m having trouble in locating the cause for a memory leak in my script. I have a simple repository method which increments a \'count\' column in my entity by X amount:

6条回答
  •  粉色の甜心
    2020-12-31 08:00

    I had similar issues with a memory leak. I'm running Doctrine in a Symfony 5.2 project. More specific, I built a never-ending Command which is processing entries from one table, retrieves entries from another table, and creates 2 new entries in other tables. (Event Processing)

    I solved my leakage problems in two steps.

    1. I use the --no-debug when running the command (as already suggested by Jonathan)
    2. I added at the end of the loop $this->entityManager->clear();

    In order to see and identify the leakages, I used the following line to output the current memory usage:

    $output->writeln('Memory Usage in MB: ' . memory_get_usage() / 1024 / 1024);
    

    Maybe this helps anyone still fighting with leakages.

提交回复
热议问题