title: Can't make Delete to work on C++
body: <p>I'm trying to destroy objects in C++, but I can't make it to work. I have a few questions about how to clear memory in C++, something that I didn't have to do in Java because of GarbageCollector.</p>
  
  <p>I have the following destructor and attributes for my Image class:</p>
  
  <pre><code>Class Image{
  public:
  Image(int w, int h){
      width = w; height = h;
      pixels = new int[w*h];
  }
      ~Image() {
          delete [] pixels;
  }
  private:
  
          int *pixels; 
          int width, height;
  
  }
  </code></pre>
  
  <p>This is what i'm doing with my Images:</p>
  
  <pre><code>void keyboard(unsigned char key, int x, int y){
          Image* sub1 = new Image(1,1);
          Image* sub2 = new Image(1,1);
      if (key == 'd' &amp;&amp; camadas[1].getpXf() &lt; camadas[1].getImage().getWidth() - gameWidth/2) {
  
          sub1 = &amp;camadas[0].ScrollH(true);
          sub2 = &amp;camadas[1].ScrollH(true);
          sub1-&gt;plot(sub2-&gt;getPixels(), 0, 0, gameWidth, gameHeight);
          lastScreen = sub1-&gt;getPixels();
          glutPostRedisplay();
      }
      if (key == 'a' &amp;&amp; camadas[1].getpXi() &gt; 0) {
  
          sub1 = &amp;camadas[0].ScrollH(false);
          sub2 = &amp;camadas[1].ScrollH(false);
          sub1-&gt;plot(sub2-&gt;getPixels(), 0, 0, gameWidth, gameHeight);
          lastScreen = sub1-&gt;getPixels();
          glutPostRedisplay();
  
      }
      delete sub1
      delete sub2;
  
  }
  </code></pre>
  
  <p>My questions are:</p>
  
  <ol>
  <li><p>Why are my commands "delete" not working? What I need to do to make them work? The "delete" don't get highlighted on Visual Studio 2015, and when the codes get to it the Visual Studio stops my program and says that "There is a Breakpoint".</p></li>
  <li><p>Is there a better way to control the memory my program is using? I am using too much memory because every time I press "a" or "d" I capture another photo of an Image, and I get lots of memory use because I'm not deleting these Images from the memory.</p></li>
  </ol>
  
  <p>There are more stuff on the class Image and there is even 1 more class (Layer), but for my question I don't think they will help.</p>