title: How are arrays stored and deleted in memory?
body: <p>I made a 2D array on the heap of some objects:</p>
  
  <p>Step (1)</p>
  
  <pre><code>Obj **arr = new Obj *[n];
  
  for (int i=0;i&lt;n;i++)
  {
      arr[i] = new Obj[n];
  }
  </code></pre>
  
  <p>// so this creates 2D arr[n][n]...then when I delete it:</p>
  
  <p>Step (2)</p>
  
  <pre><code>for (int i=0;i&lt;n;i++)
  {
      delete [] arr[i];
  }
  delete [] arr;
  </code></pre>
  
  <p>So I'm still not sure what this delete does. Does it run the destructor of Obj and flag the OS telling it this is now available memory.</p>
  
  <p>Now what I REALLY do not understand is that when I do Step (1) again (after I deleted), I get these objects initialized to weird values, yet this doesn't happen the first time I do it (all zero-initialized). Did I just get lucky the first time?</p>