title: Vector of shared pointers , memory problems after clearing the vector
body: <p>I realized that after calling <code>vector.clear()</code> which hold shared pointers, the destructors of the object which own by <code>shared_ptr</code> is not being released. </p>
  
  <p>Code example can be seen below . Even <code>vector.clear()</code> being called, destructor called after shared pointer goes beyond the scope.My question is - do I have to delete all smart pointers inside the vector manually by resetting them? Is there any easier way that you can advice ? </p>
  
  <pre><code>Output :   
  
  constructor
  I am here
  destructor
  
  Code:
  
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  using namespace std;
  
  class A
  {
  public:
      A(){cout &lt;&lt; "constructor" &lt;&lt; endl;};
      ~A(){cout &lt;&lt; "destructor"  &lt;&lt; endl;};
  };
  
  int main( )
  {
      shared_ptr&lt;A&gt; sharedptr (new A);
      std::vector&lt;shared_ptr&lt;A&gt; &gt; test;
      test.push_back(sharedptr);
  
      test.clear();
      cout &lt;&lt; "I am here" &lt;&lt; endl;
  }
  </code></pre>