title: When is C++ destructor called on an object in heap?
body: <p>Suppose a class and its usage </p>
  
  <pre><code>#include &lt;vector&gt;
  class B
  {
   public:
       B() {temp = 0;}; // implemented 
      ~B() {} ; // implmented 
   private : 
        int temp; 
        // it holds a std::bitset , a std::vector.. It is quite large in size.
  };
  
  class A 
  {
      private:
      std::vector&lt;B*&gt; * _data ; 
      public: 
      A()
      {
         _data = new std::vector&lt;B*&gt;(0); 
      }
      ~A()
       {
           for(unsigned int idx_ = 0; idx_ &lt; _data-&gt;size(); ++idx_)
                delete _data-&gt;at(idx_);
           delete _data ; 
       }
       void addB()
       {
            B * temp = new B();
            _data-&gt;push_back(temp);
       }
  }
  
  
  
  int main()
  {
     A temp; 
     temp.addB(); 
      // Do something 
  }
  </code></pre>
  
  <p>My question is does this code leak memory ? Also suppose another usage </p>
  
  <pre><code>int main()
  {
       A * temp = new A(); 
       temp-&gt;addB(); 
  
       delete temp ; // 1 
  }
  </code></pre>
  
  <p>Is 1 here required ? If I have a pointer to the heap and the pointer goes out of scope is the destructor called on the element in heap. I just want to be sure about this point. 
  Thank you !</p>