title: Local array inside Heap object - C++
body: <p>For the purpose of the example - I have a few classes:</p>
  
  <pre><code>class RGB {
      short value[3];
  };
  
  class AbstractImage {
      protected:
          int n_pixels;
  
      public:
          virtual ~AbstractImage() {};
  }
  
  template &lt;typename T&gt; class Image : public AbstractImage {
      T* data;
  
      public:
      Image&lt;T&gt;(int n) { n_pixels=n; data=new T[n_pixels]; }
      virtual ~Image&lt;T&gt;() {delete[] data;}
  
      // also provided is a copy constructor and assignment operator overloading
  
  };
  typedef class Image&lt;RGB&gt; ColorImage;
  </code></pre>
  
  <p>Is there a memory leak from Image? Do I need to release the RGB objects one by one with delete? Or isn't there a leak?</p>
  
  <p>From my understanding: data points to content created on the heap (using the word "new") which holds an RGB object array with a size of n_pixels (which has an array called "value" with 3 cells - also on the heap). Which means that we need to delete each object one by one.</p>