title: How to avoid memory leak with shared_ptr?
body: <p>Consider the following code.</p>
  
  <pre><code>using boost::shared_ptr;
  struct B;
  struct A{
      ~A() { std::cout &lt;&lt; "~A" &lt;&lt; std::endl; }
      shared_ptr&lt;B&gt; b;    
  };
  struct B {
      ~B() { std::cout &lt;&lt; "~B" &lt;&lt; std::endl; }
      shared_ptr&lt;A&gt; a;
  };
  
  int main() {
      shared_ptr&lt;A&gt; a (new A);
      shared_ptr&lt;B&gt; b (new B);
      a-&gt;b = b;
      b-&gt;a = a;
  
      return 0;
  }
  </code></pre>
  
  <p>There is <em>no output</em>. <em>No desctructor</em> is called. Memory leak.
  I have always believed that the smart pointer helps avoid memory leaks.</p>
  
  <p>What should I do if I need cross-references in the classes?</p>