title: Memory leak when executing Doctrine query in loop
body: <p>I'm having trouble in locating the cause for a memory leak in my script. I have a simple repository method which increments a 'count' column in my entity by X amount:</p>
  
  <pre><code>public function incrementCount($id, $amount)
  {
      $query = $this
          -&gt;createQueryBuilder('e')
          -&gt;update('MyEntity', 'e')
          -&gt;set('e.count', 'e.count + :amount')
          -&gt;where('e.id = :id')
          -&gt;setParameter('id', $id)
          -&gt;setParameter('amount', $amount)
          -&gt;getQuery();
  
      $query-&gt;execute();
  }
  </code></pre>
  
  <p>Problem is, if I call this in a loop the memory usage balloons on every iteration:</p>
  
  <pre><code>$entityManager = $this-&gt;getContainer()-&gt;get('doctrine')-&gt;getManager();
  $myRepository = $entityManager-&gt;getRepository(MyEntity::class);
  while (true) {
      $myRepository-&gt;incrementCount("123", 5);
      $doctrineManager-&gt;clear();
      gc_collect_cycles();
  }
  </code></pre>
  
  <p>What am I missing here? I've tried <code>-&gt;clear()</code>, as per Doctrine's <a href="http://doctrine-orm.readthedocs.org/en/latest/reference/batch-processing.html" rel="noreferrer">advice on batch processing</a>. I even tried <code>gc_collect_cycles()</code>, but still the issue remains.</p>
  
  <p>I'm running Doctrine 2.4.6 on PHP 5.5.</p>