How do I remove variables from the heap?
I have been doing some research and still cannot find a solution to my problem. As far as I know, when we declare variables outside the function, they are allocated inside the heap, and this memory is not released until the end of execution; unless we specifically do it with a function delete
. I tried the following features to make variables declared in the beginning of the code, and none of them did not work (getting debugging errors dbgdel.cpp): delete
, delete []
, free()
. What am I doing wrong?
I'll embed below the summarized version of the code. Any help is appreciated. Thank!
(I know that globals are usually not desirable when programmed correctly, but this is not my piece of code, I'm just trying to fix it as it is.)
#include <stdio.h>
#include <conio.h>
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
#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 (&z_base);
}
source to share