Memory-Leak? #7473

Closed
opened 2026-01-22 15:52:07 +01:00 by admin · 1 comment
Owner

Originally created by @fungus75 on GitHub (Feb 8, 2025).

Bug Report

Q A
Version 2.19.8

Summary

After importing a huge amount of data into the database we call for any entry within a entity a function that updates some fields. So the function is very simple (developed as symfony console command) but it looks like doctrine is loosing some memory. Because at around 10'000 iterations we got an Out-Of-Memory-Error from php.

Current behavior

Looks like Memory was lost, because we got an out-of-memory-error:

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /var/www/app/vendor/doctrine/persistence/src/Persistence/Reflection/RuntimeReflectionProperty.php on line 46

Expected behavior

Memory should not be lost.

How to reproduce

this is the function:

        $repo = $this->entityManager->getRepository($entityName);
        $batch_pos = 0;
        while (true) {
            $batch = $repo->createQueryBuilder('i')
                ->setMaxResults($batch_size)
                ->where('i._q = \'\' ')
                ->getQuery()
                ->getResult();

            $items = count($batch);
            $batch_pos+=$items;
            if ($items == 0) break;
            foreach ($batch as $item) {
                $item->updateSimpleSearch();
            }
            $this->entityManager->flush();
            $this->entityManager->clear();
            $this->entityManager->getUnitOfWork()->clear();
        }

the updateSimpleSearch in that case looks like:

$this->_q = $this->positionstext;

Originally created by @fungus75 on GitHub (Feb 8, 2025). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |-------------------------------------------- | ------ | Version | 2.19.8 #### Summary After importing a huge amount of data into the database we call for any entry within a entity a function that updates some fields. So the function is very simple (developed as symfony console command) but it looks like doctrine is loosing some memory. Because at around 10'000 iterations we got an Out-Of-Memory-Error from php. #### Current behavior Looks like Memory was lost, because we got an out-of-memory-error: Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /var/www/app/vendor/doctrine/persistence/src/Persistence/Reflection/RuntimeReflectionProperty.php on line 46 #### Expected behavior Memory should not be lost. #### How to reproduce this is the function: ``` $repo = $this->entityManager->getRepository($entityName); $batch_pos = 0; while (true) { $batch = $repo->createQueryBuilder('i') ->setMaxResults($batch_size) ->where('i._q = \'\' ') ->getQuery() ->getResult(); $items = count($batch); $batch_pos+=$items; if ($items == 0) break; foreach ($batch as $item) { $item->updateSimpleSearch(); } $this->entityManager->flush(); $this->entityManager->clear(); $this->entityManager->getUnitOfWork()->clear(); } ``` the updateSimpleSearch in that case looks like: ` $this->_q = $this->positionstext;`
admin closed this issue 2026-01-22 15:52:08 +01:00
Author
Owner

@greg0ire commented on GitHub (Feb 8, 2025):

First, I'd like to point out that you don't seem to be doing a lot of interesting stuff with $batch_pos. Also, this feels like a support question more than a bug report, despite its label, so let me convert it. And finally, maybe this will help: https://www.doctrine-project.org/projects/doctrine-orm/en/3.3/reference/batch-processing.html

@greg0ire commented on GitHub (Feb 8, 2025): First, I'd like to point out that you don't seem to be doing a lot of interesting stuff with `$batch_pos`. Also, this feels like a support question more than a bug report, despite its label, so let me convert it. And finally, maybe this will help: https://www.doctrine-project.org/projects/doctrine-orm/en/3.3/reference/batch-processing.html
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7473