CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.”
CppCon2 HN recommenders · recommended in 4 months, 2016–2025
talk · advanced · evergreen · 2016–2025 on HN
Herb Sutter's CppCon 2016 talk on lifetime safety in C++, aiming for code free of leaks and dangling pointers by default. It covers smart pointers, ownership, reference counting pitfalls and deferred reclamation resembling garbage collection.
HN cites it in memory management debates for its treatment of reference counting problems, destructor stack overflows and deferred pointers.
Up next
6 mo on HNCppCon 2017: Carl Cook “When a Microsecond Is an Eternity: High Performance Trading Systems in C++”
CppCon
5 HN recommender · 2017–2025
2 mo on HNCppCon 2014: Herb Sutter "Back to the Basics! Essentials of Modern C++ Style"
CppCon
2 HN recommender · 2014–2021
7 mo on HNCppCon 2015: Kate Gregory “Stop Teaching C"
CppCon
7 HN recommender · 2016–2025
4 mo on HNEdwin Brady - Idris 2 - Type-driven Development of Idris
Curry On!
4 HN recommender · 2019–2023
5 mo on HNEric Bier Demonstrates Cedar
Computer History Museum
3 HN recommender · 2020–2025
3 mo on HNCppCon 2016: Dan Saks “extern c: Talking to C Programmers about C++”
CppCon
2 HN recommender · 2017–2025
4 mo on HN"A Political History of X" - Keith Packard (LCA 2020)
linux.conf.au
4 HN recommender · 2020–2025
6 mo on HNRailsConf 09: Robert Martin, "What Killed Smalltalk Could K
O'Reilly
5 HN recommender · 2012–2026
11 mo on HNCppCon 2015: Andrei Alexandrescu “std::allocator...”
CppCon
7 HN recommender · 2017–2025
12 mo on HNLexical Scanning in Go - Rob Pike
GoogleFOSSSydney
13 HN recommender · 2012–2025
10 mo on HNCppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”
CppCon
9 HN recommender · 2018–2026
9 mo on HNRustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West
Rust Programming Language
9 HN recommender · 2018–2023
12 comments from Hacker News
Check all of Herb Sutter's CppCon videos from 2015-2016, especially this one: ▶ this video He does a great job of walking through the thought process of deciding which of the options makes sense in different situations.
On single core without threading. If you add multi-threading and multi-core, there is lock contention for every single memory access to update the related counter. Additionally, if there is a big data structure in use, reaching zero will trigger a cascade deletion events reaching stop-the-world like effect. Which, depending on how the deletion was implemented, might trigger a stack overflow in very deep structures. Herb Sutter has a very interesting talk about the bad issues of reference counting and how to work around them. CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.” ▶ this video There are multiple ways to optimize reference counting, like deferred counting, cycle collectors and a couple of others, which when you are done with all them, ends up being quite similar to having a tracing GC anyway.
Herb Sutter has a nice talk about how RAII can cause stack overflows or stop-the-world pauses if used badly. ▶ this video
Reference counting isn't deterministic in the presence of large complex data structures. You will know when memory gets deleted, but not how long it will take, nor how much stack space the destructors will require to run. Enjoy Herb Sutter's "Leak-Freedom in C++... By Default." at CppCon 2016, where he explains how those issues affect C++ and goes on to implement a tracing GC. ▶ this video
Herb Sutter gave a really great talk on this: ▶ this video He has 3 guidelines: 1. Prefer scoped lifetimes by default (local members) 2. Else prefer unique_ptr and containers 3. Else consider shared_ptr His whole talk gives examples that show the flexibility of unique_ptr and how modern C++ can express ownership. See slide 5 here: link
Regarding being "deterministic", CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.” ▶ this video
Several attempts have been made already, the problem is overcomming the community's resistance to have one in the box, recently they have removed the APIs introduced in C++11. It is also interesting how Herb Sutter avoiding making the comparision between deferred deallocation and GC algorithms on his talk until the last section. "CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.”" ▶ this video
We have to agree to disagree then. Having to create borrow checker friendly data structures doesn't bring anything to the table when writing GUI applications (including design tooling), distributed applications (Akka, Orleans, Erlang style, RDMS SP), CLI tooling, compiler tooling.... In what concerns languages with automatic memory management and support for value types, my list is somehow different, D, Nim, C#, F#, Swift, Go, Linear Haskell, Ocaml with Effects, Eiffel, Common Lisp. And I leave Herb's talk regarding those issues with RC types, "CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.” ▶ this video
About the same, Herb Sutter has a talk how that can even trigger stack overflow if the destructors are not written with care. "CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.” ▶ this video By the way, C++/WinRT uses background threads to handle cascade deletions of COM references exactly because of this.
Yeah, right. CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.” ▶ this video Better making use of the best practices advised by Herb, otherwise those destructors are going to surprise you.
> just because you don't like pointers, does not mean the rest of us can't use them perfectly safely. I actually use pointers quite safely. I just no longer see a need to ever return an allocation from `new` to a raw pointer unless I'm implementing my own pointer class. Herb Sutter's correct [0]. `std::unique_ptr` or `std::shared_ptr` or some other pointer container should __always__ hold new-allocated objects. Just like you should __always__ wear your seatbelt. It's no danger to you or anyone else, it's slightly inconvenient, and it saves a metric ton of headaches about "what if?". Because in reality a pointer container explicitly marks the scope of the allocation and if you're not wanting to use C++'s scoping rules then why are you using C++? [0] ▶ this video
Yet all the languages with a tracing GC wipe the floor of Swift's reference counting implementation. "35C3 - Safe and Secure Drivers in High-Level Languages" link link The subject of Herb's talk was actually going through all the reference counting problems to introduce in the end a lightweight implementation of deferred pointers, which isn't nothing more than basic tracing GC. ▶ this video