title: What's the fastest way to clear a std::list of dynamic objects?
body: <p>I have a list defined like:</p>
  
  <pre><code>std::list&lt;int *&gt; m_ilist;
  </code></pre>
  
  <p>and I add <code>int</code>s to the list:</p>
  
  <pre><code>m_ilist.push_back (new int (x));
  </code></pre>
  
  <p>I want to destruct the vector and delete the memory that was allocated for each element.</p>
  
  <p>Which one is better:</p>
  
  <ol>
  <li><p>Doing a loop through the list, calling delete on each iterator. After this calling clear():</p>
  
  <pre><code>for (...) { delete *it; } m_ilist.clear ();
  </code></pre></li>
  <li><p>Doing a loop but calling erase on the iterator:</p>
  
  <pre><code>for (...) { delete *it; m_ilist.erase (); }
  </code></pre></li>
  </ol>
  
  <p><em>Better</em> would be defined as quicker /  faster / less processing.</p>
  
  <p>Thanks.</p>