unique_ptr<X> f()
{
unique_ptr<X> p(new X); // or {new X} but not = new X
// do something - maybe throw an exception
return p; // the ownership is transferred out of f()
}
When the exception throw-ed, why we care about the existence of Object X, why we care about the memory it occupied?
The process will terminated soon after the handling of the exception, and the memory will be released, why we care about this?