M
Mihai Oltean
Hi
I wrote a C++Builder program that throws/catch many exceptions
(let's say 1.000.000/ hours). The problem is that I think that is a
bug in the Borland C++Builder exception handling mechanism.
If I catch an exception with catch(...) the memory is never freed! so
my computer can quickly get memory-exhausted.
Here is the code that generates the problem. In VC++ I don't have this
problem. Neither Delphi. I've managed to solve it somehow (as shown in
the second part), but I think that this is not a solution, mainly
because the program is slower in the second case and I'm not sure that
I catch all exceptions.
Does anybody else has another solution to my problem?
thanks,
mihai
#include <vcl.h>
#pragma hdrstop
//-------------------------------------------------------------------
--------
#pragma argsused
int main(int argc, char* argv[])
{
int a = 4;
int b = 0;
int c;
// the case where the memory is not freed
for (int i = 0; i < 1000000; i++)
try{
c = a/b;
}
catch(...){ // with this I catch all exceptions
c = 1;
}
/*
// the case when the memory is freed
for (int i = 0; i < 1000000; i++)
try{
c = a/b;
}
catch(Exception &e){
c = 1;
e.Free(); //Borland says "never call Free()"!
}
*/
return 0;
}
//-------------------------------------------------------------------
--------
I wrote a C++Builder program that throws/catch many exceptions
(let's say 1.000.000/ hours). The problem is that I think that is a
bug in the Borland C++Builder exception handling mechanism.
If I catch an exception with catch(...) the memory is never freed! so
my computer can quickly get memory-exhausted.
Here is the code that generates the problem. In VC++ I don't have this
problem. Neither Delphi. I've managed to solve it somehow (as shown in
the second part), but I think that this is not a solution, mainly
because the program is slower in the second case and I'm not sure that
I catch all exceptions.
Does anybody else has another solution to my problem?
thanks,
mihai
#include <vcl.h>
#pragma hdrstop
//-------------------------------------------------------------------
--------
#pragma argsused
int main(int argc, char* argv[])
{
int a = 4;
int b = 0;
int c;
// the case where the memory is not freed
for (int i = 0; i < 1000000; i++)
try{
c = a/b;
}
catch(...){ // with this I catch all exceptions
c = 1;
}
/*
// the case when the memory is freed
for (int i = 0; i < 1000000; i++)
try{
c = a/b;
}
catch(Exception &e){
c = 1;
e.Free(); //Borland says "never call Free()"!
}
*/
return 0;
}
//-------------------------------------------------------------------
--------