Hi to everybody,
I'm writing a c++ based program on Ubuntu OS using code::blocks IDE and g++ compiler.
I'm a beginner with this language so this may be a dumb question, but I've searched both the forum and the web but nothing seems to fix my problem.
I've got some issues using delete operator while trying to de-allocate memory.
This is the part of code that doesn't seem to work:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
try{AIC=new float*[Ne];}
catch (bad_alloc xa)
{cout << "Error! Allocation ---> FAULT\n"; cin.get(); }
for (i=0; i<Ne; i++)
{
try{AIC[i]=new float[Ne];}
catch (bad_alloc xa){cout << " Error! Allocation ---> FAULT\n";cin.get();break;}
}
//Here's the code that works on AIC which I haven't report
for (i=0; i<Ne; i++)
{
delete [] AIC[i];
}
delete [] AIC;
|
the code is compiled without any problem and the program runs like everything is working perfectly.
But I've noticed, using Linux system monitor utility, that the heap isn't actually released when delete is invoked., and this memory leak obviously may cause a crash in the following part of the code, when I try to store other variables.
So the question is: am I using delete in an appropriate way or it may be something else?
Moreover I get trouble when the heap is filled, I thought that a virtual memory would be automatically created when the heap is full but this don't happen and I get an inevitable crash.
thank you all
Giulio