Board index » cppbuilder » Exceptions are leaked!?!?

Exceptions are leaked!?!?


2006-09-15 02:35:35 PM
cppbuilder59
Given the following code in BCB6, I get numerous leaks reported by AQTime.
(See the comments for where leaks are reported and where they are not).
Please note that there are several different kinds of exceptions defined.
One inherits from Exception, and two do not. Some initialize AnsiString's
with constants, some do not. The incidence of leaks in each case is rather
strange. Comment out the 'continue' statements and the leaks go away.
I suspect the compiler is at fault, because in my real application (which
needs to run continuously, uninterrupted), I can see memory usage is growing
consistenly over time. I've never let it run for days at a time myself, but
I have customers who have, and they are claiming that the application
eventually simply dies.
I would just as soon submit a QC report, but I don't even know how to
describe it! Can someone please explain what is going on? Is this a known
bug in C++Builder?
#include <vcl.h>
class ExceptionX : public Exception
{
public:
ExceptionX() // leak reported here
: Exception( "X" ) {} // leak reported here
};
class ExceptionY
{
AnsiString Y;
public:
ExceptionY() : Y( "Y" ) {} // leak reported here
};
class ExceptionZ
{
AnsiString Z;
public:
ExceptionZ( AnsiString C="Z" ) : Z(C) {}
};
void TestExceptionLeaks( void )
{
for ( int c='V'; c<='Z'; ++c )
{
try
{
if ( c=='V' )
throw ExceptionZ(); // leak reported here (twice)
if ( c=='W' )
throw ExceptionZ(); // no leak reported
if ( c=='X' )
throw ExceptionX(); // two leaks (both reported in ExceptionX
constructor)
if ( c=='Y' )
throw ExceptionY(); // one leak reported here (and another in
ExceptionY constructor)
if ( c=='Z' )
throw ExceptionZ("Z"); // no leak reported
}
catch( ExceptionX &e )
{
continue;
}
catch( ExceptionY &e )
{
continue;
}
catch( ExceptionZ &e )
{
continue;
}
}
}
#pragma argsused
int main(int argc, char* argv[])
{
TestExceptionLeaks();
return 0;
}
- Dennis
 
 

Re:Exceptions are leaked!?!?

Dennis Jones wrote:
Quote
I would just as soon submit a QC report, but I don't even know how to
describe it! Can someone please explain what is going on? Is this a
known bug in C++Builder?
Yes. Most of these are I believe fixed in BDS.
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

Re:Exceptions are leaked!?!?

Dennis Jones wrote:
Quote
Given the following code in BCB6, I get numerous leaks reported by AQTime.
(See the comments for where leaks are reported and where they are not).
Try using exceptions based on std::exception with std::string when needed.
It may help you resolve leaking issues.
Darko
 

{smallsort}

Re:Exceptions are leaked!?!?

Andrue Cope [TeamB] wrote:
Quote
Dennis Jones wrote:

>I would just as soon submit a QC report, but I don't even know how
>to describe it! Can someone please explain what is going on? Is
>this a known bug in C++Builder?

Yes. Most of these are I believe fixed in BDS.
And if you are not planning to upgrade to BCB2006 any time soon, you
will find far fewer exception-leaks if you turn off function inlining.
With BCB6, all our code was released as a 'debug build', primarily for
this reason. After a while, we found the benefit of QAing and
releasing code with full debug features (including asserts) - exactly
as the dev team wrote it - simplified a lot of support issues. Works
well given we have a known, small group of end users, may well not
apply in all cases ;?
--
AlisdairM(TeamB)
 

Re:Exceptions are leaked!?!?

On Fri, 15 Sep 2006 09:00:41 +0100, "Andrue Cope [TeamB]"
< XXXX@XXXXX.COM >wrote:
Quote
Yes. Most of these are I believe fixed in BDS.
looks like there are still plenty of leaks in the code generated with
bcb2006 as revealed with aqtime
--
Vladimir Ulchenko aka vavan
 

Re:Exceptions are leaked!?!?

"Darko Miletic" < XXXX@XXXXX.COM >wrote in message
Quote
Dennis Jones wrote:
>Given the following code in BCB6, I get numerous leaks reported by
>AQTime.
>(See the comments for where leaks are reported and where they are not).

Try using exceptions based on std::exception with std::string when needed.

It may help you resolve leaking issues.
I doubt it. That was actually my first inclination. I tested the case of a
simple exception class, not derived from "Exception", containing no data
members. It still leaked.
- Dennis
 

Re:Exceptions are leaked!?!?

"Alisdair Meredith[TeamB]"
<alisdair.meredith@ XXXX@XXXXX.COM >wrote in message
Quote
Andrue Cope [TeamB] wrote:

>Dennis Jones wrote:
>
>>I would just as soon submit a QC report, but I don't even know how
>>to describe it! Can someone please explain what is going on? Is
>>this a known bug in C++Builder?
>
>Yes. Most of these are I believe fixed in BDS.

And if you are not planning to upgrade to BCB2006 any time soon, you
will find far fewer exception-leaks if you turn off function inlining.

With BCB6, all our code was released as a 'debug build', primarily for
this reason.
The main application, and this sample application are both built with debug
information, or I wouldn't have been to identify the source of the leaks!
So I don't think that will help.
- Dennis
 

Re:Exceptions are leaked!?!?

"Alisdair Meredith[TeamB]"
<alisdair.meredith@ XXXX@XXXXX.COM >wrote in message
Quote
Andrue Cope [TeamB] wrote:

>Dennis Jones wrote:
>
>>I would just as soon submit a QC report, but I don't even know how
>>to describe it! Can someone please explain what is going on? Is
>>this a known bug in C++Builder?
>
>Yes. Most of these are I believe fixed in BDS.
Yes, it would appear this is fixed in BDS. No leaks are reported by AQTime
5 when the test app is built with BDS.
- Dennis
 

Re:Exceptions are leaked!?!?

Dennis Jones wrote:
Quote
The main application, and this sample application are both built with
debug information, or I wouldn't have been to identify the source of
the leaks! So I don't think that will help.
Note that the specific problem is function inlining, not the missing
debug information! If you are running a 'standard' debug build then
this is still probably not much more help. On the other hand, if you
are running a custom/release build with debug info turned on, it might
be worth checking the state of "inline function expansion" in the
project options.
--
AlisdairM(TeamB)
 

Re:Exceptions are leaked!?!?

"Alisdair Meredith[TeamB]"
<alisdair.meredith@ XXXX@XXXXX.COM >wrote in message
Quote
Dennis Jones wrote:

>The main application, and this sample application are both built with
>debug information, or I wouldn't have been to identify the source of
>the leaks! So I don't think that will help.

Note that the specific problem is function inlining, not the missing
debug information! If you are running a 'standard' debug build then
this is still probably not much more help. On the other hand, if you
are running a custom/release build with debug info turned on, it might
be worth checking the state of "inline function expansion" in the
project options.
I'm not...I ust click the "Full Debug" button and leave the "Disable inline
expansions" checked by default.
- Dennis