title: Retrieve all rows from table in doctrine
body: <p>I have table with 100 000+ rows, and I want to select all of it in doctrine and to do some actions with each row, in symfony2 with doctrine I try to do with this query:</p>
  
  <pre><code>    $query = $this-&gt;getDefaultEntityManager()
          -&gt;getRepository('AppBundle:Contractor')
          -&gt;createQueryBuilder('c')
          -&gt;getQuery()-&gt;iterate();
  
      foreach ($query as $contractor) {
          // doing something
      }
  </code></pre>
  
  <p>but then I get memory leak, because I think It wrote all data in memory.</p>
  
  <p>I have more experience in ADOdb, in that library when I do so:</p>
  
  <pre><code>$result = $ADOdbObject-&gt;Execute('SELECT * FROM contractors');
     while ($arrRow = $result-&gt;fetchRow()) {
          // do some action
     }
  </code></pre>
  
  <p>I do not get any memory leak.</p>
  
  <p>So how to select all data from the table and do not get memory leak with doctrine in symfony2 ?</p>
  
  <blockquote>
    <p>Question EDIT</p>
  </blockquote>
  
  <p>When I try to delete foreach and just do iterate, I also get memory leak:</p>
  
  <pre><code>$query = $this-&gt;getDefaultEntityManager()
              -&gt;getRepository('AppBundle:Contractor')
              -&gt;createQueryBuilder('c')
              -&gt;getQuery()-&gt;iterate();
  </code></pre>