From:             herkimer112 at yahoo dot dk
Operating system: WinXP
PHP version:      5.2.6
PHP Bug Type:     Performance problem
Bug description:  Large memory leak when creating tree-like data structures

Description:
------------
When creating tree-like data structures, where each member
is a node with a parent and children[] member,
the memory is not released when the tree is overwritten.

Example:
rootNode has children node1 and node2
node1 and node2 have parent rootNode




Reproduce code:
---------------
class myNode_class {
  public $myChildren = array();
  public $myParent = null;
  
  function &addChild(&$node,$key) {
    $this->myChildren[$key] = $node;
    $node->myParent = $this;
  }  
}

function buildTree() {
  $tree = new myNode_class($treeName);
  for ($i=1;$i<100;$i++) {
    $tree->addChild(new myNode_class(),$i);
  }
}

function memleaktest() {
  for ($j=1;$j<=10;$j++) {
    buildTree();
    echo 'Memory usage iteration '.$j.' '.memory_get_usage()."<br>";
  }
}

memleaktest();


Expected result:
----------------
Memory usage iteration 1 97824
Memory usage iteration 2 97824
Memory usage iteration 3 97824
etc.


Actual result:
--------------
Memory usage iteration 1 97824
Memory usage iteration 2 128056
Memory usage iteration 3 158208
Memory usage iteration 4 188360
Memory usage iteration 5 218512
Memory usage iteration 6 248664
Memory usage iteration 7 278816
Memory usage iteration 8 308968
Memory usage iteration 9 339120
Memory usage iteration 10 369272

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

Reply via email to