Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The short answer to this question is that <strong>none of these values are a reliable indicator of how much memory an executable is actually using, and none of them are really appropriate for debugging a memory leak.</strong></p> <p><strong>Private Bytes</strong> refer to the amount of memory that the process executable has <em>asked for</em> - not necessarily the amount it is <em>actually using</em>. They are "private" because they (usually) exclude memory-mapped files (i.e. shared DLLs). But - here's the catch - they don't necessarily exclude memory <em>allocated by those files</em>. There is no way to tell whether a change in private bytes was due to the executable itself, or due to a linked library. Private bytes are also <strong>not</strong> exclusively physical memory; they can be paged to disk or in the standby page list (i.e. no longer in use, but not paged yet either).</p> <p><strong>Working Set</strong> refers to the total <strong>physical</strong> memory (RAM) used by the process. However, unlike private bytes, this also includes memory-mapped files and various other resources, so it's an even less accurate measurement than the private bytes. This is the same value that gets reported in Task Manager's "Mem Usage" and has been the source of endless amounts of confusion in recent years. Memory in the Working Set is "physical" in the sense that it can be addressed without a page fault; however, the standby page list is <em>also</em> still physically in memory but not reported in the Working Set, and this is why you might see the "Mem Usage" suddenly drop when you minimize an application.</p> <p><strong>Virtual Bytes</strong> are the total <strong>virtual address space</strong> occupied by the entire process. This is like the working set, in the sense that it includes memory-mapped files (shared DLLs), but it also includes data in the standby list and data that has already been paged out and is sitting in a pagefile on disk somewhere. The total virtual bytes used by every process on a system under heavy load will add up to significantly more memory than the machine actually has.</p> <p>So the relationships are:</p> <ul> <li>Private Bytes are what your app has actually allocated, but include pagefile usage;</li> <li>Working Set is the non-paged Private Bytes plus memory-mapped files;</li> <li>Virtual Bytes are the Working Set plus paged Private Bytes and standby list.</li> </ul> <p>There's another problem here; just as shared libraries can allocate memory inside your application module, leading to potential false positives reported in your app's Private Bytes, <em>your</em> application may also end up allocating memory inside the <em>shared</em> modules, leading to false <em>negatives</em>. That means it's actually possible for your application to have a memory leak that never manifests itself in the Private Bytes at all. Unlikely, but possible.</p> <p>Private Bytes are a reasonable <strong>approximation</strong> of the amount of memory your executable is using and can be used to help <em>narrow down</em> a list of potential candidates for a memory leak; if you see the number growing and growing constantly and endlessly, you would want to check that process for a leak. This cannot, however, <em>prove</em> that there is or is not a leak.</p> <p>One of the most effective tools for detecting/correcting memory leaks in Windows is actually <a href="http://msdn.microsoft.com/en-us/library/x98tx3cf(VS.80).aspx" rel="noreferrer">Visual Studio</a> (link goes to page on using VS for memory leaks, not the product page). <a href="http://www-01.ibm.com/software/awdtools/purify/" rel="noreferrer">Rational Purify</a> is another possibility. Microsoft also has a more general <a href="http://msdn.microsoft.com/en-us/library/dd744766(VS.85).aspx" rel="noreferrer">best practices document</a> on this subject. There are more tools listed in this <a href="https://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows">previous question</a>.</p> <p>I hope this clears a few things up! Tracking down memory leaks is one of the most difficult things to do in debugging. Good luck.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload