title: PHP Simple HTML Dom Parser Memory Leak / Usage
body: <p>I'm trying to use PHP Simple HTML Dom Parser to parse some information from some sites. Does not matter what and where. But it seems, that there is some HUGE memory problem with it. I managed to cut the html code to only 6kB, but script that finds some elements and saves them to database takes even 700MB of ram and over 1GB of virtual memory! I read somewhere that I should use ->clear() to free up some memory, but seems that this is not the case.</p>
  
  <p>I use <code>str_get_html()</code> once and 5 times using <code>-&gt;find()</code> assigning the result to variable.</p>
  
  <pre><code>$main_html = str_get_html($main_site);
  $x = $main_html-&gt;find(...);
  $y = $main_html-&gt;find(...);
  
  etc.
  </code></pre>
  
  <p>I tried to use for example <code>$y-&gt;clear()</code> after using $y but I get an error <code>PHP Fatal error:  Call to a member function clear() on a non-object</code> even tho <code>$y</code> does exist and <code>if($y)</code> is true. Even <code>foreach($y) echo $y-&gt;plaintext</code> does return <code>plaintext</code> of <code>$y</code>.</p>
  
  <p>From htop:</p>
  
  <pre><code>PID USER     PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
  8839 username    20   0 1068M  638M   268 R 23.0  8.0  0:08.41 php myscript.php
  </code></pre>
  
  <p>What is wrong?</p>
  
  <p>Simple test:</p>
  
  <pre><code>echo "(MEM:".memory_get_usage()."-&gt;";
  $product = $p-&gt;find('a',0)-&gt;href;
  echo memory_get_usage()."-&gt;";
  unset($product);
  $p-&gt;clear();
  unset($p);
  echo memory_get_usage().")";
  </code></pre>
  
  <p>The result is:</p>
  
  <p><code>(MEM:11865648-&gt;11866192-&gt;11865936)</code></p>
  
  <p>More readable form:</p>
  
  <pre><code>11865648-&gt;
  11866192-&gt; (+544 in total)
  11865936 (+288 in total)
  </code></pre>
  
  <p>Of course I can't use $product->clear() as it says that <code>PHP Fatal error: Call to a member function clear() on a non-object</code></p>