小编ash*_*azg的帖子

如果SplObjectStorage在仍然附加对象的同时进行销毁,是否会留下内存泄漏引用?

如果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?
Run Code Online (Sandbox Code Playgroud)

php spl

5
推荐指数
1
解决办法
323
查看次数

标签 统计

php ×1

spl ×1