title: imagejpeg memory exhaustion
body: <p>I'm creating thumbnails cycling through a lot of images, when I find a large image I get:</p>
  
  <pre><code>Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 13056 bytes)
  </code></pre>
  
  <p>Now <strong>I already know</strong> how to circumvent this with:</p>
  
  <pre><code>ini_set('memory_limit', '-1');
  </code></pre>
  
  <p>What I want to know is why it exhaust the memory! Is there some debug tools that will show me exactly when memory is exhausting? And specifically that will show me if there are variables/arrays that are killing my memory?</p>
  
  <p>OR, are there better way to resize images other then:</p>
  
  <pre><code>$thumb=imagecreatetruecolor($newwidth,$newheight); 
  $source=imagecreatefromjpeg($imgfile);
  imagecopyresampled($thumb,$source,0,0,0,0,$newwidth,$newheight,$width,$height);
  imagejpeg($thumb,$destinationfile,85);
  </code></pre>
  
  <p>?</p>
  
  <p>Thank you very much!</p>