M
Martin
Hi.
I've found a few topics on this subject, but still not sure and decided
to post mine.
Here's my example:
#include <iostream>
using namespace std;
class A
{
public:
A() { throw 0; }
};
int main()
{
try
{
A *pA = new A;
delete pA;
}
catch (...)
{
}
}
An object of class A is created in the heap, but the constructor throws
an exception. I know, that the destructor of the class won't be called,
and really I don't need that, because my class itself doesn't allocates
any resources. But what happens with memory allocated for the object
itself? After all, the first thing done by 'new' is allocating enough
memory for the object. So, who's responsible for deallocating it in
such a case?
Thanks in advance
Martin
I've found a few topics on this subject, but still not sure and decided
to post mine.
Here's my example:
#include <iostream>
using namespace std;
class A
{
public:
A() { throw 0; }
};
int main()
{
try
{
A *pA = new A;
delete pA;
}
catch (...)
{
}
}
An object of class A is created in the heap, but the constructor throws
an exception. I know, that the destructor of the class won't be called,
and really I don't need that, because my class itself doesn't allocates
any resources. But what happens with memory allocated for the object
itself? After all, the first thing done by 'new' is allocating enough
memory for the object. So, who's responsible for deallocating it in
such a case?
Thanks in advance
Martin