title: How does the OS X 'heap' command line utility collect its information?
body: <p>The OS X 'heap' command line utility can apparently enumerate the different malloc zones and the individual malloc'ed chunks of any running process. It does not require linking with any special debug library or have any debug heap environment variables set for the targeted process.</p>
  
  <p>Which underlying mechanism does it use to do that? All the malloc debugging APIs I could find need to have hooks set from inside the process, special debug libraries linked or debugging environment variables set prior to launching the process. From what I can tell the source code for the utility is not available, and numerous searches on Google and Apple.com did not reveal anything helpful.</p>
  
  <p>I'm mostly interested in obtaining the actual malloc'ed memory sum, as the resident size of a process can often be significantly inflated from what has actually been requested by the application code.</p>
  
  <p>Thanks!</p>