title: Environment Specific Memory Leak
body: <p>I'm running into a memory leak issue during a batch processing script using Doctrine 2 /Symfony.</p>
  
  <p>First: I AM aware how to properly manage the entity manager to avoid memory leaks, and for some reason my live server is able to run the following code without running into this issue. However on my local development environment (PHP 5.4.7) running the following command causes my memory use to balloon.</p>
  
  <p>edit:</p>
  
  <p>Is there any php ini, apache, osx, mysql confirguration that could possibly be causing this issue as I'm now at a complete loss.</p>
  
  <p>Note that the code is the same in both locations - so the only thing causing this difference is some sort of logging (x-debug or automatic logging of SQL) that I'm unaware of.</p>
  
  <p>live server is running PHP 5.4.6 vs 5.4.7 locally
  live server is running centos 6, vs OSX locally</p>
  
  <p>I'm running the following the command in prod mode with debug off...</p>
  
  <pre><code>&lt;?php
  
  namespace Vendor\Bundle\MemoryTestBundle\Command;
  
  use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  use Symfony\Component\Console\Input\InputInterface;
  use Symfony\Component\Console\Output\OutputInterface;
  
  class MemTestCommand extends ContainerAwareCommand
  {
      protected function configure()
      {
          $this
              -&gt;setName('mem:test')
              -&gt;setDescription('Shows memory use ballooning out of control');
      }
  
      protected function execute(InputInterface $input, OutputInterface $output)
      {
          $em = $this-&gt;getContainer()-&gt;get('doctrine.orm.entity_manager');
  
          $q = $em-&gt;createQuery('SELECT s FROM VendorMemoryTestBundle:SimpleEntity s');
          $iterableResult = $q-&gt;iterate();
  
          $i = 0;
  
          while (($row = $iterableResult-&gt;next()) !== false) {
              $i++;
              if ($i%50 == 0){
                  echo sprintf('Memory usage: %01.0fKB.', memory_get_usage(true) / 1024) . PHP_EOL;
                  $em-&gt;clear();
              }
              $em-&gt;detach($row[0]);
          }
      }
  }
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>Memory usage: 72192KB.
  Memory usage: 72448KB.
  Memory usage: 72448KB.
  Memory usage: 72704KB.
  Memory usage: 73216KB.
  Memory usage: 73472KB.
  Memory usage: 73472KB.
  Memory usage: 73728KB.
  Memory usage: 73728KB.
  Memory usage: 73984KB.
  Memory usage: 73984KB.
  Memory usage: 74240KB.
  etc...
  </code></pre>