php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51168 Userland Cyclic Reference with Nested DateTime are not garbage collected
Submitted: 2010-02-27 16:45 UTC Modified: 2010-03-01 14:39 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kontakt at beberlei dot de Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.3.1 OS: Linux/Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kontakt at beberlei dot de
New email:
PHP Version: OS:

 

 [2010-02-27 16:45 UTC] 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



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-27 16:49 UTC] kontakt at beberlei dot de
Sorry it seems this is a duplicate of http://bugs.php.net/bug.php?id=49700
 [2010-02-28 16:46 UTC] jani@php.net
Ok. 
 [2010-03-01 14:39 UTC] fa@php.net
Uhm, original bug seemed to be MacOS X only - now this reads Linux/Ubuntu - further testing needed I think.
 [2010-06-08 23:23 UTC] srinatar@php.net
Automatic comment from SVN on behalf of srinatar
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300294
Log: - Fixed Bug #51168 (fails to compile with Sun Studio)
 # C99 standard supports inline keyword and supported by
 # by major compilers like GCC, HP C, IBM C and Sun C
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 05:01:38 2025 UTC