2008-03-15 02:36:34 +08:00
|
|
|
--TEST--
|
2008-07-08 16:16:09 +08:00
|
|
|
GC 029: GC and destructors
|
2010-03-04 01:53:15 +08:00
|
|
|
--INI--
|
|
|
|
zend.enable_gc=1
|
2008-03-15 02:36:34 +08:00
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
class Foo {
|
2020-02-04 05:52:20 +08:00
|
|
|
public $bar;
|
|
|
|
public $x = array(1,2,3);
|
|
|
|
function __destruct() {
|
|
|
|
if ($this->bar !== null) {
|
|
|
|
$this->x = null;
|
|
|
|
unset($this->bar);
|
|
|
|
}
|
|
|
|
}
|
2008-03-15 02:36:34 +08:00
|
|
|
}
|
|
|
|
class Bar {
|
2020-02-04 05:52:20 +08:00
|
|
|
public $foo;
|
2008-03-15 02:36:34 +08:00
|
|
|
function __destruct() {
|
|
|
|
if ($this->foo !== null) {
|
|
|
|
unset($this->foo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
$foo = new Foo();
|
|
|
|
$bar = new Bar();
|
|
|
|
$foo->bar = $bar;
|
|
|
|
$bar->foo = $foo;
|
|
|
|
unset($foo);
|
|
|
|
unset($bar);
|
|
|
|
var_dump(gc_collect_cycles());
|
2019-08-01 18:55:39 +08:00
|
|
|
var_dump(gc_collect_cycles());
|
2008-03-15 02:36:34 +08:00
|
|
|
?>
|
2019-08-01 18:55:39 +08:00
|
|
|
--EXPECT--
|
|
|
|
int(0)
|
|
|
|
int(1)
|