Memory allocated out side of try and Delete in finally
-
I had a memory allocated out side a try block and I am trying to delete in finally? Should there be any issue with this. I am getting access violation while deleting
char *heap = new char [50];
try
{......
}
finally(...)
{delete[] heap; // access violation
} -
I had a memory allocated out side a try block and I am trying to delete in finally? Should there be any issue with this. I am getting access violation while deleting
char *heap = new char [50];
try
{......
}
finally(...)
{delete[] heap; // access violation
}It should work when not modifying (which includes deleting) the
heap
pointer inside thetry
block. If you are not doing such (just comment the code inside thetry
block to check it), you should tell us which compiler you are using becausefinally
is not defined by the C++ standard. -
It should work when not modifying (which includes deleting) the
heap
pointer inside thetry
block. If you are not doing such (just comment the code inside thetry
block to check it), you should tell us which compiler you are using becausefinally
is not defined by the C++ standard.I am using RAD Studio code gear
-
I am using RAD Studio code gear
So it is the BCC compiler. According to the __finally (C++) - RAD Studio[^] it should be
__try
and__finally
. When omitting the leading underscores the code should not even compile becausetry
requires acatch
and__try
requires an__except
or__finally
. Is it still not working with the correct syntax and an empty__try
block? Then you might ask this in a BCC specific forum like Recent Topics - Forum - Embarcadero Community[^].