title: How to Solve Shared_ptr Cyclic Without Making it Weak_ptr?
body: <p>I have been debugging this memory leak for hours, and just find out that there's a cyclic in the program. </p>
  
  <p>The methods introduced on the Internet is to make <code>shared_ptr</code> a <code>weak_ptr</code>, but it's defined in this assignment that we should use <code>shared_ptr</code>. </p>
  
  <p>Basically, the program is a file system. Like when you type <code>cd .</code>, you'll enter the current address. </p>
  
  <ol>
  <li><code>currentAddress</code>, which is an inode_ptr that points to the current address.</li>
  <li><code>directory</code>, which is defined as <code>map&lt;string, inode_ptr&lt;node&gt;&gt;</code>. <code>directory.first</code> is the filename/directory name like <code>.</code>, <code>..</code>, or <code>fileA</code> And <code>directory.second</code> is an <code>inode_ptr</code>, same as <code>currentAddress</code>.</li>
  </ol>
  
  <p>So what I'm trying is to put <code>pair&lt;".",  currentAddress&gt;</code> into <code>directory</code>. </p>
  
  <p>And <code>currentAddress</code> should also point to <code>directory</code></p>
  
  <p>How to avoid memory leak in this case, but not to use <code>weak_ptr</code>? Thanks!</p>