 <p>Also, read here: <a href="http://docs.doctrine-project.org/en/2.0.x/reference/batch-processing.html" rel="nofollow">http://docs.doctrine-project.org/en/2.0.x/reference/batch-processing.html</a></p> <p>It suggests to use $em->clear() after every bulk of operations. (which should give the same effect as Besnik suggested).</p> <p>From the previously mentioned link:</p> <blockquote> <p>Bulk inserts in Doctrine are best performed in batches, taking advantage of the transactional write-behind behavior of an EntityManager. The following code shows an example for inserting 10000 objects with a batch size of 20. You may need to experiment with the batch size to find the size that works best for you. Larger batch sizes mean more prepared statement reuse internally but also mean more work during flush.</p> </blockquote>