title: c++ delete dynamic matrix
body: <p>I have this code to allocate and initialize:</p>
  
  <pre><code>nw = new int*[V];
  
  for (w = 0; w &lt; V; w++) {
  
  nw[w] = new int[K];
  
  for (k = 0; k &lt; K; k++) 
  
    nw[w][k] = 0;
  }
  </code></pre>
  
  <p>and this to free memory:</p>
  
  <pre><code>if (nw) {
   for (int w = 0; w &lt; V; w++) {  
    if (nw[w]) 
  delete nw[w];      
  }
  </code></pre>
  
  <p>The program compile and runs, but, when its try to deallocate memory, fails.
  The program not always fails at the same value of w.</p>
  
  <p>Any ideas?</p>