Memory Management in C++: Differences in allocating shared_ptr using new vs make_shared

52 Views Asked by At

I'm used to allocate shared pointer this way: std::shared_ptr<Person> ptr = std::make_shared<Person>("Name", 27); As I saw in other project, they allocate the pointer in a different way, and I want to understand the memory management behind each one.

1. std::shared_ptr<Person> ptr(new Person("Name", 27));
2. std::shared_ptr<Person> ptr = std::shared_ptr<Person>(new Person("Name", 27));
3. std::shared_ptr<Person> ptr = std::make_shared<Person>("Name", 27);

All of these options manage their memory without needed to de delete them manually ?

0

There are 0 best solutions below