title: How do virtual destructors work?
body: <p>Few hours back I was fiddling with a Memory Leak issue and it turned out that I really got some basic stuff about virtual destructors wrong! Let me put explain my class design.</p>
  
  <pre><code>class Base
  {
    virtual push_elements()
    {}
  };
  
  class Derived:public Base
  {
  vector&lt;int&gt; x;
  public:
     void push_elements(){ 
        for(int i=0;i &lt;5;i++)
           x.push_back(i); 
     }
  };
  
  void main()
  {
      Base* b = new Derived();
      b-&gt;push_elements();
      delete b;
  }
  </code></pre>
  
  <p>The bounds checker tool reported a memory leak in the derived class vector. And I figured out that the destructor is not virtual and the derived class destructor is not called. And it surprisingly got fixed when I made the destructor virtual. Isn't the vector deallocated automatically even if the derived class destructor is not called? Is that a quirk in BoundsChecker tool or is my understanding of virtual destructor wrong?</p>