title: What is callback hell in C++ and why will it leak memory?
body: <p>I've been watching Herb Sutter's CppCon 2016 talk, in which he gave an example <a href="https://www.youtube.com/watch?v=JfmTagWcqoE&amp;t=37m00s" rel="nofollow noreferrer">around 37 minutes in</a>, something like this:</p>
  
  <pre><code>void f(shared_ptr&lt;T&gt; &amp; ptr)
  {
      obj.on_draw([=]() { ... }
  }
  </code></pre>
  
  <p>He then says, </p>
  
  <blockquote>
    <p>I've heard it called callback hell, where you register a callback and
    it has a strong owner--it happens to be a garbage-collected pointer
    but it's a strong owner--but then you never get rid of it and it's
    just stored there forever and now the object will never go away.</p>
  </blockquote>
  
  <p>So he is saying that it's called callback hell and it will leak objects.
  But I don't quite understand what's wrong with this code and why it will leak. Could someone explain this to me?</p>
  
  <p>I've looked at others answers on stackoverflow, but they all seem to be about concurrency. </p>