memory usage problem
<p>I am working on optimizing the memory usage of my codes and I found a problem that I do not understand. Please let me know what you think.</p>

<p>Code:</p>

<pre><code>typedef map &lt;pair&lt;string, int&gt;, vector&lt;pair&lt;int, float&gt; &gt; &gt; TDM;

void parsefile (TDM &amp; my_map, string in_file); // parse input file and put it in the data map
float CheckMemUsage (void); // check memory usage by extracting /proc/self/stat info


int main (int argc, char *argv[]) {
  TDM my_map;
  string infile = "xxx";

  printf ("INFO: Memory usage before parse file: %.2fM.\n", CheckMemUsage ());
  parsefile (my_map, in_file);
  printf ("INFO: Memory usage after parse file: %.2fM.\n", CheckMemUsage ());

  for (TDM::iterator it=my_map.begin(); it!=my_map.end(); ++it) {
    vector&lt;pair&lt;int, float&gt; &gt; ().swap (it-&gt;second);
  }
  TDM ().swap (my_map);
  printf ("INFO: Memory usage after delete map: %.2fM.\n", CheckMemUsage ());
}
</code></pre>

<p>The report of this program:</p>

<pre><code>INFO: Memory usage before parse file: 13.46M.
INFO: Memory usage after parse file: 203.53M.
INFO: Memory usage after delete map: 132.59M.
</code></pre>

<p>In the function "parsefile", I only use string, vector, pair, map stuffs, without new any memory. So after this program, I assume that only my_map is in memory. After deleting my map, the memory usage should return to before parsing file status (13.46M). But it still reports a 132.59M. What is this 132M for? Is there sth wrong in my program?</p>

<p>Thanks a lot for your time. </p>
