Skip to content


DDC-1783: Combination of Query::iterate() and ObjectHydrator results in continued memory growth after clearing the entity manager #2436

doctrinebot opened this Issue · 3 comments

2 participants


Jira issue originally created by user ebernhardson:

To reproduce:

Start with the doctrine sandbox. Remove address relation from user. append the following to index.php

for($i=0;$i<100000;$i) {
$user = new User;
$user->setName('foo' . $i);

$query = $em->getRepository('Entities\User')->createQueryBuilder('u')->getQuery();
$i = 0;
echo "Running test:" . PHPEOL . "start: " . memory_get_usage() . PHPEOL;
foreach($query->iterate() as $row) {
if ($i === 100000) {
echo "end: " . memoryget_usage() . PHPEOL;

echo PHPEOL . "done" . PHPEOL;

The result i get is

Running test:
start: 7658928
end: 32601776

Adding my own custom hydrator which simply extends and resets the ObjectHydrator::_identifierMap (may cause bugs, i dont know) i get

Running test:
start: 7658768
end: 10724984

This originally came up while working with an process to import an existing doctrine table of ~10M rows into elastic search. I realize going through the ORM will never be the most efficient, but there is room for more efficiency. With larger objects and larger result sets the memory growth is much more pronounced.


Comment created by ebernhardson:

code paste above didn't work out so well. Attached is a .tgz of the sandbox used above.


Comment created by @beberlei:



Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.2.3 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.