Link Counting in php - how does it work?

I am trying to understand this article " PHP Manual → Features → Garbage Collection " unfortunately, not everything is clear to me.

1.

To avoid the need to call checking garbage cycles with each possible reduction, the algorithm instead puts all possible zvals in the “root buffer”.

but what if

<?php
$a = new \stdClass(); (1)
$a = new \stdClass();

Then I assume that the first object will become a "lost" zval, like

no_symbol: (refcount = 1, is_ref = 1) = stdObject

Will such "lost" zvals be added to the root buffer or not? There is no handler for them.

2.

Variables created in the function area, what happened to them?
Example:

<?php
function test($a = 'abc') {
    $c = 123;

    return 1; 
}

test(); 
echo 'end';

$a $c gc? refcount, 1. ? , ( ?)

3. ?
Ex

<?php
$a = array('abc');
$a[] =& $a;
unset($a);

(refcount=1, is_ref=1)=array (
   0 => (refcount=1, is_ref=0)='abc',
   1 => (refcount=1, is_ref=1)=...
)
+4
1

1) , , , .

echo memory_get_usage().'<br/>';
$a = new stdClass();
echo memory_get_usage().'<br/>';
$a = new stdClass();
echo memory_get_usage().'<br/>';

2) gc'ed , :

echo memory_get_usage().'<br/>';
function test($a = 'abc') {
    $c = 123;

    return 1;
}
echo memory_get_usage().'<br/>';
test();
echo memory_get_usage().'<br/>';

3), $a, . NULL, .

echo memory_get_usage().'<br/>';
$a = array('abc');
echo memory_get_usage().'<br/>';
$a[] =& $a;
echo memory_get_usage().'<br/>';
$a = null;
unset($a);
echo memory_get_usage().'<br/>';
+1

Source: https://habr.com/ru/post/1524961/


All Articles