I have a function which uses 0.5 MB memory each time I run it. So I decided to investigate it step by step by watching the Windows task manager at the same time. I noticed after these lines:
int **banned;
banned=new int*[vertices];
for(i=0;i<vertices;i++)
banned[i]=new int[k_colors];
It uses 0,5 MB memory. Then I decided to delete it before the return
line:
for(i=0;i<vertices;i++)
for(j=0;j<k_colors;j++)
delete []banned[j];
delete[]banned;
It was 8,5 MB memory using beginning of the function. After allocation, it became 9 MB, but after the delete part, it was still 9 MB. And I execute this function in the whole program 1000 times. Then it is getting killed by OS. Any idea why is that and how can I solve it?
EDIT: Here the main()
part:
int main()
{
srand(time(0));
input();
initialize();
for(int i = 0; i < MAX_GENERATION; i++)
{
parents = selection(TS);
population = cross_over(parents, PC);
mutation(PM);
elite=tabu_search(population);
elitism(); //270 MB memory using each time.
}
fclose(pFile);
return 0;
}
Above, in elitism()
function's first line are allocation part, and last lines are delete
part.