Bruintje Beer a écrit :
Does the code below solve memory leaks on variable m if there is an
exception thrown or do I have to cleanup the auto_ptr myself ?
As soon as you put your pointer in auto_ptr, you're assured it will be
deleted when the auto_ptr is destroyed.
void A::f()
{
try
{
auto_ptr<Objectm(new Object());
some exception thrown
}
catch(MyException& ex)
{
// some stuff
}
}
In this code, the auto_ptr is destroyed at the end of the try block
(exception thrown or not), so there is no memory leak.
Cheers,
--
Vincent Jacques
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème"
Devise Shadock