I was working on c++ program to construct molecules and perform vector operations on them.To get the probability in some particular problem, I had to take multiple random observations and calculate ratio. My program works fine when I took 1000 outcomes, but got stuck nearly forever when I took 10000 outcomes (Far more than 10 times the time). Also The computer became irresponsive. So to find out where the problem was, after a bit of debugging I came down to this: (My Vector rotation Algorithm) `
int main()
{
Vector v1(3,4,0);
geom3D::EulerAngle EA(90,0,0);
int K=120000;
for(int i=0;i<K;i++)
{
v1=rotateVector(v1,EA);
if(i%3000==0)
cout << i << "\n";
}
cout << "Done\n";
}
It was supposed to print 3000,6000 ... and I expected it would at regular intervals, however, I got the same problem here too: Up 51000, it prints pretty fast, then again the computer becomes irresponsive. My guess was that it is about memory allocation, that it was allocating a lot of memory in the rotateVector() which it wasn't freeing, so I tried adding delete statements wherever I could. But I still couldn't find a good solution to this. Is such behaviour normal? Is there a solution? Also, are delete statement all that I can do to free memory?