title: Does it take time to deallocate memory?
body: <p>I have a C++ program which, during execution, will allocate about 3-8Gb of memory to store a hash table (I use tr1/unordered_map) and various other data structures.</p>
  
  <p>However, at the end of execution, there will be a long pause before returning to shell.</p>
  
  <p>For example, at the <strong>very end</strong> of my main function I have</p>
  
  <pre><code>std::cout &lt;&lt; "End of execution" &lt;&lt; endl;
  </code></pre>
  
  <p>But the execution of my program will go something like</p>
  
  <blockquote>
    <p>$ ./program<br>
    do stuff...<br>
    End of execution<br>
    <strong>[long pause of maybe 2 min]</strong><br>
    $ -- returns to shell</p>
  </blockquote>
  
  <p>Is this expected behavior or am I doing something wrong? </p>
  
  <p>I'm guessing that the program is deallocating the memory at the end. But, commercial applications which use large amounts of memory (such as photoshop) do not exhibit this pause when you close the application.</p>
  
  <p>Please advise :)</p>
  
  <p>Edit: The biggest data structure is an <code>unordered_map</code> keyed with a <code>string</code> and stores a <code>list</code> of <code>integers</code>. </p>
  
  <p>I am using <code>g++ -O2</code> on linux, the computer I am using has 128GB of memory (with most of that free). There are a few giant objects</p>
  
  <p>Solution: I ended up getting rid of the hashtable since it was almost full anyways. This solved my problem. </p>