title: Why "Allowed memory size exhausted"?
body: <p>I am writing a batch script and get a <code>Allowed memory size of 134217728 bytes exhausted</code> error.</p>
  
  <p>I don't understand why the memory is filling up. I tried unsetting the <code>$row</code> variable, but that didn't change a thing. Here is my code:</p>
  
  <pre><code>// ... (sql connection)
  $result = mysql_query("SELECT * FROM large_table");
  
  while ($row = mysql_fetch_array($result)) {
      echo $row['id'] . PHP_EOL;
      unset($row);
  }
  </code></pre>
  
  <p>(simplified code)</p>
  
  <p>Why does the memory fill up, and how can I avoid it?</p>
  
  <p>Note: this is a batch script. This is normal that I have to handle data like that (go through 1 million lines).</p>
  
  <p><strong>Update: The out of memory happens around the 400 000th line, so this has got to be something in the loop? I'd like to avoid having to implement the paging if possible.</strong></p>