#51168 [Opn->Bgs]: Userland Cyclic Reference with Nested DateTime are not garbage collected
ID: 51168
Updated by: jani@php.net
Reported By: kontakt at beberlei dot de
-Status: Open
+Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Linux/Ubuntu
PHP Version: 5.3.1
New Comment:
Ok.
Previous Comments:
------------------------------------------------------------------------
[2010-02-27 16:49:35] kontakt at beberlei dot de
Sorry it seems this is a duplicate of
http://bugs.php.net/bug.php?id=49700
------------------------------------------------------------------------
[2010-02-27 16:45:34] kontakt at beberlei dot de
Description:
------------
When one of the participants of a cyclic reference holds a reference to
a DateTime instance, the GC seems to be unable to do its job.
NOTE: Even without a DateTime reference memory keeps increasing slowly
but steadily. This is not the case as soon as either $a->b = $b or $b->a
= $a is commented out, i.e. the cyclic reference is removed. So even
though the GC seems to work almost perfectly (without a DateTime
reference), a small leak remains.
The leakage also occurs with PDO, however not with other php internal
objects.
Reproduce code:
---------------
class A {
public $b;
public $ref;
function __construct() {
$this->ref = new DateTime; // "large" leak. comment out for small
leak.
}
}
class B {
public $a;
}
for ($i=1; $i<=200000; ++$i) {
$a = new A;
$b = new B;
$a->b = $b; // comment out to avoid any leakage, with or without
DateTime, doesnt matter.
$b->a = $a; // comment out to avoid any leakage, with or without
DateTime, doesnt matter.
if ($i % 10000 == 0) {
gc_collect_cycles();
printf('----- Memory usage after %d iterations: %2.2f MB' .PHP_EOL,
$i, memory_get_usage() / 1024 / 1024);
}
}
Expected result:
----------------
----- Memory usage after 10000 iterations: 0.79 MB
----- Memory usage after 20000 iterations: 0.79 MB
----- Memory usage after 30000 iterations: 0.79 MB
----- Memory usage after 40000 iterations: 0.79 MB
----- Memory usage after 50000 iterations: 0.79 MB
----- Memory usage after 60000 iterations: 0.79 MB
----- Memory usage after 70000 iterations: 0.79 MB
----- Memory usage after 80000 iterations: 0.79 MB
----- Memory usage after 90000 iterations: 0.79 MB
----- Memory usage after 100000 iterations: 0.79 MB
Actual result:
--------------
----- Memory usage after 10000 iterations: 4.53 MB
----- Memory usage after 20000 iterations: 8.38 MB
----- Memory usage after 30000 iterations: 12.15 MB
----- Memory usage after 40000 iterations: 15.90 MB
----- Memory usage after 50000 iterations: 19.65 MB
----- Memory usage after 60000 iterations: 23.40 MB
----- Memory usage after 70000 iterations: 27.15 MB
----- Memory usage after 80000 iterations: 30.90 MB
----- Memory usage after 90000 iterations: 34.65 MB
----- Memory usage after 100000 iterations: 38.41 MB
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=51168&edit=1
Thread (4 messages)