C++ Memory Leak new Operator
I need to identify which objects are destroyed AND if there is any memory leaks on this code.
1 2 3 4 5 6
|
void myfunc()
{
Photo a(1, 2);
Photo* pt = new Photo(2, 3);
throw runtime_error("to test the exception");
}
|
My answer was
the object is destroyed after the function end
, by automatically calling the destructor of the class Photo.
There is a memory leak.
We did not delete pt that is dynamically allocated with new operator.
So we need to add delete pt; at the end of function.
Is my anwer is correct?
Yes.
a
is cleaned up automatically.
pt
leaks.
Topic archived. No new replies allowed.