php-src/Zend/tests/gc_028.phpt
Nikita Popov b58d74547f Rerun GC if destructors encountered
Since PHP 7.4 objects that have a destructor require two GC runs
to be collected. Currently the collection is delayed to the next
automatic GC run. However, in some cases this may result in a large
increase in memory usage, as in one of the cases of bug #79519.

See also bug #78933 and bug #81117 where the current behavior is
unexpected for users.

This patch will automatically rerun GC if destructors were encountered.
I think this should not have much cost, because it is very likely that
objects on which the destructor has been called really are garbage,
so the extra GC run should not be doing wasted work.

Closes GH-5581.
2021-06-09 14:53:14 +02:00

34 lines
545 B
PHP

--TEST--
GC 028: GC and destructors
--INI--
zend.enable_gc=1
--FILE--
<?php
class Foo {
public $bar;
function __destruct() {
if ($this->bar !== null) {
unset($this->bar);
}
}
}
class Bar {
public $foo;
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());
?>
--EXPECT--
int(1)