Will the memory allocation covered by smart pointer is guaranteed to be freed up in event of an exception thrown such as below? I tried executing the code putting breakpoint at shared_ptr destructor but i did not see it getting called. I think the memory should be cleaned up by itself. Am i right or it wont be cleaned up?
void test(std::shared_ptr<int> sptr)
{
throw "exception";
}
int main()
{
std::shared_ptr<int> ptr(new int(1));
test();
}
Aucun commentaire:
Enregistrer un commentaire