Custom Deleters and Make Functions
Use std::make_unique, std::make_shared, and custom deleters for non-memory resources.
Why Custom Deleters?
Not every resource is freed by delete. File handles, sockets, OS-specific resources, and arrays each need a different cleanup function.
Default Deleter for unique_ptr
By default unique_ptr<T> uses delete. For arrays, use unique_ptr<T[]> which calls delete[].
All lessons in this course
- Why Smart Pointers Replace Raw new delete
- unique_ptr Exclusive Ownership
- shared_ptr and weak_ptr Shared Ownership
- Custom Deleters and Make Functions