title: Free Memory Occupied by Std List, Vector, Map etc
body: <p>Coming from a C# background, I have only vaguest idea on memory management on C++-- all I know is that I would have to free the memory manually. As a result my C++ code is written in such a way that objects of the type <code>std::vector</code>, <code>std::list</code>, <code>std::map</code> are freely instantiated, used, but not freed.</p>
  
  <p>I didn't realize this point until I am almost done with my programs, now my code is consisted of the following kinds of patterns:</p>
  
  <pre><code>struct Point_2
  {
      double x;
      double y;
  };
  
  struct Point_3
  {
      double x;
      double y;
      double z;
  };
  
  list&lt;list&lt;Point_2&gt;&gt; Computation::ComputationJob
      (list&lt;Point_3&gt;pts3D, vector&lt;Point_2&gt;vectors)
  {
      map&lt;Point_2, double&gt; pt2DMap=ConstructPointMap(pts3D);
      vector&lt;Point_2&gt; vectorList = ConstructVectors(vectors);
      list&lt;list&lt;Point_2&gt;&gt; faceList2D=ConstructPoints(vectorList , pt2DMap);
      return faceList2D;
  }
  </code></pre>
  
  <p>My question is, must I free <strong><em>every.single.one</em></strong> of the list usage ( in the above example, this means that I would have to free <code>pt2DMap</code>, <code>vectorList</code> and <code>faceList2D</code>)? That would be very tedious! I might just as well rewrite my <code>Computation</code> class so that it is less prone to memory leak.</p>
  
  <p>Any idea how to fix this?</p>