title: PHP sf.1.4 Propel 1.6: memory leaking while looping results
body: <p>I am working with symfony 1.4 + propel 1.6 and I want to export (index) all my user database to ElasticSearch.</p>
  
  <p>I have written all the script and everything is working okay, besides one problem. I make a loop that repeats about 20.000~ times and with everytime the memory_usage increases.</p>
  
  <p>Problem is: it shouldn't, because I am destroying all the references.</p>
  
  <p>I think Propel is leaving somewhere a static reference to the every object I create. Can't find it though, because I already disabled the instance pooling.</p>
  
  <p>Anybody had ever a similar problem? Maybe someone has an idea how can I debug the PHP memory limits? (webgrind doesnt) I spent last few hours on this piece of code debugging and still can't fix it.</p>
  
  <pre><code>// optimizations
      gc_enable();
      Propel::getConnection()-&gt;useDebug(false);
      Propel::disableInstancePooling();
  // the while
      $offset = 0;
      $perpage = 10;
      $c = SearchUserQuery::create()-&gt;limit($perpage);
      do {
          $rs = SearchUserPeer::doSelectStmt($c);
          while ($row = $rs-&gt;fetch(PDO::FETCH_NUM))
          {
              $instance = new SearchUser();
              $instance-&gt;hydrate($row);
              $data = $instance-&gt;toElastic(); // this line makes a lot of memory leak
              $_document = new Elastica\Document($instance-&gt;getPrimaryKey(), $data);
              $_type-&gt;addDocument($_document);
              unset($_document, $instance);
          }
          $c-&gt;offset($offset += $perpage);
      } while( $rs-&gt;rowCount() );
  </code></pre>
  
  <p>Function $instance->toElastic is sth like that:</p>
  
  <pre><code>public function toElastic()
  {
      return Array(
          'profile' =&gt; $this-&gt;toArray(BasePeer::TYPE_COLNAME, false),
          'info' =&gt; $this-&gt;getUserInfo()-&gt;toArray(BasePeer::TYPE_COLNAME, false),
          'branches' =&gt; $this-&gt;getElasticBranches(),
      );
  }
  
  /**
   * @return array(id,name)
   */
  public function getElasticBranches()
  {
      $branches = Array();
      foreach ($this-&gt;getsfGuardUser()-&gt;getUserBranchs() as $branch)
          $branches[] = Array(
              'id' =&gt; $branch-&gt;getBranchId(),
              'name' =&gt; $branch-&gt;getName()
          );
      return $branches;
  }
  </code></pre>