We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Back to Basics: C++ Smart Pointers - David Olsen - CppCon 2022
Simplify your C++ code, avoid memory leaks, and master smart pointers with expert David Olsen, covering best practices for unique_ptr, shared_ptr, and more at CppCon 2022.
-
Use
make_unique
ormake_shared
whenever possible to simplify code and avoid memory leaks. - Smart pointers can help with cleanup, but don’t rely solely on them.
- Always be mindful of ownership and who is responsible for freeing memory.
- Avoid using raw pointers unless necessary.
-
Use
unique_ptr
for ownership, but not sharing. -
Use
shared_ptr
for shared ownership, but not transfer of ownership. - Avoid pointers to single objects and arrays, instead use smart pointers.
- Null pointers are not the same as smart pointers.