mirror of
https://github.com/php/php-src.git
synced 2024-12-16 05:15:03 +08:00
b58d74547f
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.
43 lines
755 B
PHP
43 lines
755 B
PHP
--TEST--
|
|
GC 017: GC and destructors with unset
|
|
--INI--
|
|
zend.enable_gc=1
|
|
--FILE--
|
|
<?php
|
|
class Node {
|
|
public $name;
|
|
public $children;
|
|
public $parent;
|
|
function __construct($name) {
|
|
$this->name = $name;
|
|
$this->parent = null;
|
|
}
|
|
function insert($node) {
|
|
$node->parent = $this;
|
|
$this->children[] = $node;
|
|
}
|
|
function __destruct() {
|
|
var_dump($this->name);
|
|
unset($this->name);
|
|
unset($this->children);
|
|
unset($this->parent);
|
|
}
|
|
}
|
|
$a = new Node('A');
|
|
$b = new Node('B');
|
|
$c = new Node('C');
|
|
$a->insert($b);
|
|
$a->insert($c);
|
|
unset($a);
|
|
unset($b);
|
|
unset($c);
|
|
var_dump(gc_collect_cycles());
|
|
echo "ok\n"
|
|
?>
|
|
--EXPECTF--
|
|
string(1) "%s"
|
|
string(1) "%s"
|
|
string(1) "%s"
|
|
int(1)
|
|
ok
|