orm: DDC-1682: EntityManager::clear() not working as expected.

Jira issue originally created by user gcaseres:

I’ve been reading Doctrine2 Batch Processing documentation. I’ve a simplified the code and made a sample where I’m using a Repository inside the loop:

for ($i=1; $i<=10000; <ins></ins>$i) {
     $user = $this->_em->getRepository('some user class')->find($i);
     $this->_em->clear();

     //Clear variables to ensure garbage collections     
     unset($user);
     $user = null;

}

I expect that this script will consume some constant memory in all iterations, but what happens is that every iteration raises memory consumption (more iterations, more memory)… i think that the clear method has some sort of memory leak.

In my production environment (with complex script), i reach a memory limit exception even with 600MB limit… but if I clear the EntityManager on every iteration, shouldn’t memory be freed?

Sorry for my bad english.

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 16

Most upvoted comments

Comment created by brunolemos:

Fixed it by doing the following:

$this ->_em ->getConnection() ->getConfiguration() ->setSQLLogger(null);