From:             kontakt at beberlei dot de
Operating system: Linux/Ubuntu
PHP version:      5.3.1
PHP Bug Type:     Unknown/Other Function
Bug description:  Userland Cyclic Reference with Nested DateTime are not 
garbage collected

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 bug report at http://bugs.php.net/?id=51168&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=51168&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=51168&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=51168&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=51168&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51168&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=51168&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=51168&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=51168&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=51168&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=51168&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=51168&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=51168&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=51168&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=51168&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51168&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51168&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=51168&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=51168&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=51168&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=51168&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=51168&r=mysqlcfg

Reply via email to