title: Deallocating memory in a 2D array
body: <p>Suppose we have:</p>
  
  <pre><code>int** myArray = new int*[100];
  for(int i = 0; i &lt; 100; i++){
      myArray[i] = new int[3];
  }
  </code></pre>
  
  <p>What is the appropriate way to deallocate this array (which method below, if either is a correct way to do so)?</p>
  
  <p>1.</p>
  
  <pre><code>delete[] myArray;
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>for(int i = 0; i &lt; 100; i++){
      for(int j = 0; j &lt; 3; j++){
          delete myArray[i][j];
      }
  }
  delete[] myArray;
  </code></pre>
  
  <p>Intuitively it seems like we should do something like 2. since we want all of the memory we allocated to be deleted, but I'm not sure.</p>