title: How do I force my std::map to deallocate memory used?
body: <p>I'm using a std::map, and I can't seem to free the memory back to the OS. It looks like,</p>
  
  <pre><code>int main(){
    aMap m;
  
    while(keepGoing){
      while(fillUpMap){
         //populate m
      }
      doWhatIwantWithMap(m);
      m.clear();//doesnt free memory back to OS
  
      //flush some buffered values into map for next iteration
      flushIntoMap(m);
    }
  }
  </code></pre>
  
  <p>Each (fillUpmap) allocates around 1gig, so I'm very much interested in getting this back to my system before it eats up all my memory.</p>
  
  <p>Ive experienced the same with std::vector, but there I could force it to free by doing a swap with an empty std::vector. This doesn't work with map.</p>
  
  <p>When I use valgrind it says that all memory is freed, so its not a problem with a leak, since everything is cleared up nicely after a run.</p>
  
  <p>edit:</p>
  
  <p>The flush has to appear after the clear.</p>