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 delete
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): delete
, delete []
, free()
.
What am I doing wrong?
I will paste underneath a summarized version of the code. Any help is appreciated. Thank you!
(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.)
#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);
}