title: How do I delete variables from the heap?
body: <p>I have been doing some research and still can't find a solution to my problem. 
  As far as I know, when we declare variables outside of a function, they are allocated within the heap, and that memory is not freed until the end of execution; unless we specifically do so with the <code>delete</code> function. I've tried the following functions to free the variables declared at the beginning of the code and none of them worked (getting a debug error in dbgdel.cpp): <code>delete</code>, <code>delete []</code>, <code>free()</code>. 
  What am I doing wrong?</p>
  
  <p>I will paste underneath a summarized version of the code. Any help is appreciated. Thank you!</p>
  
  <p>(I know global variables are not usually desirable in proper programming, but is not my piece of code, I am  just trying to fix it as it is.)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;cv.h&gt;
  #include &lt;highgui.h&gt;
  #include &lt;cxcore.h&gt;
  #include "Viewer.h"
  ....    
  // Arrays
  float z_base [5201][5201];
  ....
  
  uchar maskThreshold [5200][5200];
  ...
  
  
  void main(){
  .....       
       delete [] z_base;
       //free (z_base);
       //delete z_base;
       //free (&amp;z_base);    
  } 
  </code></pre>