My favourite memory leak - Björn Fahller - Lightning Talks @ Meeting C++ 2023
Why Stack Overflow recommends it
Stack Overflow users link it as the source of the self-containing vector leak when asking or answering questions about self-referential CRTP vectors, self-assignment, and forward declarations.
Recommended by 0 people across 0 different months, 2023 to 2025.
What it is
A roughly four-minute lightning talk from Meeting C++ 2023 by Björn Fahller showing how C++ can leak memory without new or malloc. The trick is a struct that inherits from std::vector of itself, then swaps the vector with its own element.
What people said
Cites sandthorn · 2023-12 · Stack Overflow · on “Why can't I "destroy" CRTP vector that is "self-owned" but still can deallocate its address?”
From Björn Fahller's Ligthning Talk at CPP Meeting 2023. => [LINK] LKKmPAQFNgE [this video] It's about how one can force c++ to leak memory without touching new or even malloc . struct V : vector<V> {}; auto v = V{}; v.emplace_back(); v.swap(v.front()); // v representation becomes uint64_t[3]{ 0x0, 0x0, 0x0}, // so the vector allocation gets lost because no refs are left on the scope. So I wonder if I can manually destroy it. struct V : vector<V> {}; auto v = V{}; v.emplace_back(); v.emplace_back(); v.emplace_back(); v.emplace_back(); auto front = v.front(); v.swap(v.front()); using allocator = std::allocator<V>; using atraits = std::allocator_traits<allocator>; auto a = front.get_allocator(); at
Cites Oersted · 2024-02 · Stack Overflow · on “is a class declaration before base-clause a valid forward declaration?”
I just take the example as it from the video (and I agree with you). You can do that with any template class holding only pointer or reference to `V`. For the context: [this video] So far, it's only an intuition that it can be used in practice (inheriting from template classes holding ref or pointer to the base).
Cites alfC · 2025-08 · Stack Overflow · on “Why is copy-and-swap preferred over self-assignment check?”
TLDR; Self-assignment check is typically a required step to implemented RAII assignment properly. Self-assignment check can fail or be insufficient for RAII classes that can be assigned parts of itself. In this case, C&S can be an attractive alternative, because it is easy to implement and automatically strong-exception safe. But RAII assignment is actually more performant so it is the recommeded approach, not the other way around. RAII assignment can also be strong-exception safe, but can be trickier to implement. Definitions The premise is not well stated, and it is wrong at best. But there is still a concrete answer to the probable correct reinterpretation of your question. The premise is