Here is my program

Code: C++
class MEM{
public:
  float** GEN(void)
{
  float** X=(float**)malloc(sizeof(float)*3);
for (int Row=0; Row<3; Row++)
{
  X[Row]=(float*)malloc(sizeof(float)*3);
for (int Col=0; Col<3; Col++)
{
  X[Row][Col]=(float) rand();
}
}
return X;
free(X);
}

};

int main()
MEM test;
 for (int NT=0; NT<100; NT++)
{
  test.GEN();
}
return 0;

I found that the memory always can not be free. If the NT or 3 is very large, it will break the system. Could you help me how to free the memory in subprogram?

Thank you very much! Email: lshangxin2@student.cityu.edu.hk

Last edited by SaswatPadhi; 13Aug2009 at 05:44..