I have a c++ program that makes a simulation. The simulation is large. It needs to be ran several times.
I probably didn't take into account some memory management guidelines like passing arguments by reference to functions to avoid copies of the same data to be wasting memory, and maybe other techniques I don't even know about. But it is too late to redo the whole program again (or maybe it won't even help).
I have a program
void main(){
//Simulation consuming a lot of memory.
};
I would like something like
void main(){
for (int i=0;i<10000;i++){
//Simulation consuming a lot of memory (depending on i).
};
};
But in such a way that after each loop of the for the memory used inside is released (probably except that which is used for the program and the counter i of the for).
The memory holds fine for one repetition of the loop but not for two.
I there a way this can be done?