title: Why does my C++ program's memory usage keep growing?
body: <p>I am new to Linux and C++ and have a question about the memory usage of my application.</p>
  
  <p>My application processes a lot of real-time data, about <strong>500</strong> messages per second. </p>
  
  <p>I use std::map to manage (i.e., insert and erase) all the messages. For example,</p>
  
  <pre><code>std::map&lt;int, data_struct&gt; m_map;
  
  // when receive a new message, convert the message into a data structure
  m_map.insert(std::pair&lt;int, data_struct&gt;(message.id, data));
  
  // when need to erase a message
  iter = m_map.find(id);
  if (iter != m_map.end()) {
      m.map.erase(iter);
  }
  </code></pre>
  
  <p>The size of the m_map is roughly about <strong>2500</strong>, i.e., the application receives a lot new message at the beginning, then gradually need to erase messages. After about 10 seconds, it reaches a point that the number of new message received is about the same as the messages need to be erased. </p>
  
  <p>My question is this, after about 20 minutes, in the Linux <strong>System Monitor</strong>, I noticed the memory my application uses is about 1GB. And it seems the size doubles every 20 minutes. Is this something normal, does the application really use that much memory? Am I missing something here?</p>
  
  <p>Thanks.</p>