【发布时间】:2013-01-08 22:02:15
【问题描述】:
如果一个 SplObjectStorage 实例在仍然附加一些对象的情况下解构,它是先隐式分离对象,还是由于 SplObjectStorage 的引用导致内存泄漏那些悬空的物体?我正在尝试确定是否有必要使用用户空间代码“分离在销毁之前留下的任何内容”以防止此类内存泄漏。
$storage = new SplObjectStorage();
$x = new stdClass();
$y = new stdClass();
$storage->attach($x);
$storage->attach($y);
$storage = null;
// did not explicitly detach $x and $y... does $storage's destruction do it?
// or do the zval counts on $x and $y now off by one?
$x = null;
$y = null;
// at this point, are there two dangling references to $x and $y,
// simply because $storage did not dereference from them before destroying itself?
【问题讨论】: