What is the scope of PHP's circular reference problem, and should I worry about that?

If I use a tree structure of nodes similar to the code below, do I need to worry about the circular link?
I read that PHP uses a memory allocation mechanism that can make life very difficult for the garbage collector when there are round links.

What I want to know:

  • If my tree consists of only a few nodes, say 25, is this a problem?
  • Will memory be freed at the end of the script or am I slowly creating a problem for the server?
  • Under what circumstances will this problem have an effect during script execution?
  • Manually deleting links solves the problem, and should I always do this?
class Node {
    private $parent;
    private $children;

    function addChild( Node $child ) {
        $this->children[] = $child;
        $child->setParent( $this );
    }

    function setParent( $parent ) {
        $this->parent = $parent;
    }
}

//eg
$node0 = new Node;
$node1 = new Node;

// nodes 1 and 2 have a circular reference to each other
$node0->addChild( $node1 );
+5
4

:

  • , , 25, ?

, .

  • script ?

, .

  • script?

, - , . 25 , / , .

  • , ?

. Propel , , . , .

+4

, , ( ), , PHP .

PHP, , , , PHP-, - . .

.

+3

PHP, - - , . . , , PHP 5 , , .

+2

PHP 5.3 . , , , , .

Develop now, take precautions against explicit dereferences in the __destruct () method, and upgrade to 5.3 if necessary.

+2
source

All Articles