title: c++ memory leak with std::vectors
body: <p>I'm reading a <code>400mb</code> file into a c++ vector with the following code:</p>
  
  <pre><code>#define RAMALLOC 20000000
  struct worddata {
      std::string name;
      double ussage;
  };
  // ...
  int counter = 0;
  std::string dName;
  double dUssage;
  std::vector&lt;worddata&gt; primDataBank;
  primDataBank.resize(RAMALLOC);
  std::ifstream fIn(PATH + "output.dat");
  while (fIn &gt;&gt; dName &gt;&gt; dUssage) {
      primDataBank[counter].name = dName;
      primDataBank[counter].ussage = dUssage;
      counter++;
  }
  </code></pre>
  
  <p>I have resided the vector to a size of <code>20,000,000</code> items, so as I assign to it in the loop, the ram usage shouldn't be increasing. However when I run it, the ram usage increases rapidly.</p>
  
  <p>In the Visual Studio debugger heap snapshot, it shows me that the ram is being occupied by <code>processFrequencyData.exe!std::_Container_proxy</code>. The "allocation call stack" looks like so:</p>
  
  <p><a href="https://i.stack.imgur.com/ReWO3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ReWO3.png" alt="enter image description here"></a></p>
  
  <p>This appears to have its roots in the vector.</p>
  
  <p><strong>How can I stop my ram usage from increasing?</strong></p>
  
  <p>Thanks.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>My ram usage still increases rapidly when I comment out the lines of code in the while loop that assign values</p>
  
  <pre><code>while (fIn &gt;&gt; dName &gt;&gt; dUssage) {
      //primDataBank[counter].name = dName;
      //primDataBank[counter].ussage = dUssage;
      counter++;
  }
  </code></pre>
  
  <p>However ram usage doesn't increase when I also comment out the vector code:</p>
  
  <pre><code>//std::vector&lt;worddata&gt; primDataBank;
  //primDataBank.resize(RAMALLOC);
  </code></pre>