if I have an entity repository and invoke the findAll() method, how would I be able to free the memory afterwards? I ran a small test using $entityManager->clear(), but it did not do the job. Thanks in advance for your help!
Do you need all records? Can you filter results, so less objects are created. The problem with php sometimes is, that it won't let you free the memory until the process has ended.
You can try it with unset() if you need all records. But be aware the memory won't be free, I think the garbage collector of PHP has a problem with cycling references, doctrine I guess has such references to be powerful.
A similar question to yours with an example: Why is PHP Doctine's free() not working?
If it is a command line with mass iteration can you please try
$this->_em->detach($row[0]);
as described here: http://www.doctrine-project.org/blog/doctrine2-batch-processing