title: What is the scale of PHP's circular reference problem and should I worry about it?
body: <p>If I am using a tree structure of nodes similar to the code below, do I have to worry about the circular reference?<br>
  I have read that PHP uses a memory allocation mechanism which can make life very hard for the garbage collector when there are circular references involved.  </p>
  
  <p>What I want to know is:  </p>
  
  <ul>
  <li>If my tree consists of only a few nodes, say 25, is this a problem?</li>
  <li>Will the memory be freed at the end of the script or am I slowly creating a problem for the server?</li>
  <li>Under what circumstances will this problem have an effect during script execution?</li>
  <li>Will manually destroying the references solve the problem and should I always do it?</li>
  </ul>
  
  <pre><code>class Node {
      private $parent;
      private $children;
  
      function addChild( Node $child ) {
          $this-&gt;children[] = $child;
          $child-&gt;setParent( $this );
      }
  
      function setParent( $parent ) {
          $this-&gt;parent = $parent;
      }
  }
  
  //eg
  $node0 = new Node;
  $node1 = new Node;
  
  // nodes 1 and 2 have a circular reference to each other
  $node0-&gt;addChild( $node1 );
  </code></pre>