|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-02-27 16:49 UTC] kontakt at beberlei dot de
[2010-02-28 16:46 UTC] jani@php.net
[2010-03-01 14:39 UTC] fa@php.net
[2010-06-08 23:23 UTC] srinatar@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 20:00:01 2025 UTC |
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