c++ - Exception handling before deleting dynamic memory in a function -
i allocated dynamic memory , clearing memory @ end of function using delete operator. have exception handling before delete. how can avoid memory leak in situation.
use std::unique_ptr
or similar hold heap-allocated memory. deallocated automatically when smart pointer goes out of scope, whether or not exception thrown.
Comments
Post a Comment