If I understand correctly, when shared_ptr (from boost, tr1, std, whatever) is initialized with a pointer to a newly allocated object, the shared_ptr constructor allocates a small amount of memory to store the reference account for the pointer it manages. What happens if this distribution fails? In the following code:
class my_class {}; void my_func(shared_ptr<my_class> arg); int main(int argc, char* argv[]) { my_func(shared_ptr<my_class>(new my_class())); return 0; }
... will there be a leak of the my_class object if shared_ptr cannot allocate memory for its reference counter? Or is the shared_ptr constructor responsible for deleting the object?
c ++ memory-management smart-pointers
bythescruff
source share