title: Doctrine transaction using too much memory issue
body: <p>I keep on getting this error when running one of my scripts;</p>
  
  <blockquote>
    <p>PHP Fatal error:  Allowed memory size
    of 1073741824 bytes exhausted (tried
    to allocate 71 bytes) in ...
    lib/symfony-1.4.11/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/Statement.php
    on line 246, ...</p>
  </blockquote>
  
  <p>The following is the stripped-down version of the script that's
  triggering the error;</p>
  
  <pre><code>public function executeImportFile(sfWebRequest $request)
  {
   ini_set('memory_limit', '1024M');
   set_time_limit ( 0 );
  
   //more codes here...
  
   $files = scandir($workspace.'/'.$directory);
  
   foreach ($files as $file) {
     $path = $workspace.'/'.$directory.'/'.$file;
  
     if ($file != "." &amp;&amp; $file != "..") {
       $this-&gt;importfile($path);
     }
   }
  }
  
  
  protected function importfile($path){
  
  
   $connection =
  sfContext::getInstance()-&gt;getDatabaseManager()-&gt;getDatabase('doctrine')-&gt;getDoctrineConnection();
   $connection-&gt;beginTransaction();
   try {
  
     //more codes here...
  
  
     while ($data = $reader-&gt;read()) //reads each line of a csv file
     {
       // send the line to another private function to be processed
       // and then write to database
       $this-&gt;writewave($data);
     }
  
  
     $connection-&gt;commit();
  
   } catch (Exception $e) {
     $connection-&gt;rollback();
   }
  }
  </code></pre>
  
  <p>What the script does is basically to read all the csv files in a
  folder (which contains tens of thousands of lines each), process it,
  and the write it to the database using Doctrine's transaction.</p>
  
  <p>While I don't think I need to set the memory limit and the time limit
  in both functions, the script quits as Doctrine uses up all the the
  allocated 1GB of memory.</p>
  
  <p>It will normally stop after processing 10 files, and allocating more
  memory will allow it to process a bit more files, and will still
  crash.</p>
  
  <p>Is there anything that I'm missing here that's causing the memory not
  to free up after processing each files?</p>
  
  <p>Mohd Shakir Zakaria
  <a href="http://www.mohdshakir.net" rel="nofollow">http://www.mohdshakir.net</a></p>