【发布时间】:2014-02-26 03:50:03
【问题描述】:
我正在努力理解这篇文章“PHP Manual -> Features -> Garbage Collection” 不幸的是,对我来说几乎没有什么不清楚的。
1.
为了避免每次调用垃圾循环检查 可能减少引用计数,算法改为将所有 “根缓冲区”中可能的根 (zvals)。
万一呢
<?php
$a = new \stdClass(); (1)
$a = new \stdClass();
那我猜第一个对象会像 zval 一样“丢失”
no_symbol : (refcount=1, is_ref=1) = stdObject
这种“丢失”的 zval 是否会被添加到根缓冲区中?他们没有处理程序。
2.
在函数范围内创建的变量,它们发生了什么?
例如:
<?php
function test($a = 'abc') {
$c = 123;
return 1;
}
test();
echo 'end';
gc 启动时 $a 和 $c 发生了什么? 这些变量的 refcount 仍然设置为 1。 他们还会被删除吗?如果是,那么为什么以及如何(幕后发生了什么?)
3。
它对循环引用有何帮助?
例
<?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)=...
)
【问题讨论】: