Smart Pointers in C++
summary
Covers concrete failure modes and fixes: using ptr.get on a unique_ptr produces a double delete when ownership isn’t transferred; unique_ptr<T[]> or make_unique must be used for arrays to avoid undefined behavior; custom deleters that capture locals by reference cause use‑after‑free; shared_ptr imposes a control‑block and atomic overhead and can leak via cycles unless replaced by weak_ptr; the aliasing constructor can keep huge objects alive; tools recommended are AddressSanitizer, ThreadSanitizer, Valgrind, clang static analyzer, PVS Studio and cppcheck; prefers make_unique/make_shared and CI sanitizers.
AI-written summary · about
chapters (15)
- 0:00Introduction to pointers
- 1:04Ownership and common bugs
- 4:09Why this talk matters
- 5:30Raw pointers and RAII
- 7:07Smart pointers overview
- 8:59Unique pointer usage
- 11:11Unique pointer pitfalls
- 16:36Shared pointer fundamentals
- 19:56Circular references
- 22:38Weak pointer usage
- 25:30Shared pointer pitfalls
- 30:40Performance comparisons
- 32:49Detection tools
- 36:33Best practices
- 40:09Legacy migration strategies
related talks
01h 01mBack to Basics: Smart Pointers
01h 33mSafe and Sane C++ Types
01h 02mC++ Smart Pointers - Usage and Secrets
01h 00mBack to Basics: Pointers
01h 39m“Leak-Freedom in C++... By Default.”
51mThe Smart Pointers I Wish I Had
04mSmart Pointers in C++ Are Not Pointers
01h 02mFancy Pointers for Fun and Profit
