title: Get full details of what is using memory in PHP
body: <p>I have a PHP script that is failing with a fatal out-of-memory error.  It is a script that processes all records in the DB - it works fine up to about 10k records and then hits the memory error.</p>
  
  <p>However, I can't find out what is using up my application's memory.</p>
  
  <p>I've checked the <code>$_GLOBALS</code> array and that accounts for maybe 1 MB or so.</p>
  
  <p>I've checked the call stack at various points and have seen nothing unexpected.</p>
  
  <p>The base memory requirement for PHP plus all relevant class files, etc. is about 7MB.</p>
  
  <p>My feeling is that there is probably somewhere in the code that is resulting in variable references persisting - either deliberately (e.g. via a static cache in some class or other) or by mistake (e.g. resource handles not being freed).</p>
  
  <p>Obviously functions like <code>memory_get_usage()</code> can tell me how much memory is used at any given point in the script, and tracking this is a slow but effective way of debugging.  However, is there any way of getting details about what is actually using that memory?</p>
  
  <p>Happy to accept answers that use an external tool (e.g. XDebug) providing they give useful output (i.e. output that identifies the class/variable names rather than using PHPs internal IDs).  The output I expect would be something like you get from <code>var_dump</code>/<code>print_r</code>.</p>
  
  <p>[Note that this question is not about how to debug out-of-memory issues in general, but specifically about whether there is a way to expose the details of memory use when debugging.]</p>