#45520 [Opn->Bgs]: Large memory leak when creating tree-like data structures

From: Date: Tue, 15 Jul 2008 17:14:30 +0000
Subject: #45520 [Opn->Bgs]: Large memory leak when creating tree-like data structures
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-126781@lists.php.net to get a copy of this message
 ID:               45520
 Updated by:       jani@php.net
 Reported By:      herkimer112 at yahoo dot dk
-Status:           Open
+Status:           Bogus
 Bug Type:         Performance problem
 Operating System: WinXP
 PHP Version:      5.2.6
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php




Previous Comments:
------------------------------------------------------------------------

[2008-07-15 16:27:26] crrodriguez at suse dot de

There is no memory leak, memory is freed at script shutdown /by, looks
like the expected "by-design" behaviour.

------------------------------------------------------------------------

[2008-07-15 13:27:40] herkimer112 at yahoo dot dk

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 this bug report at http://bugs.php.net/?id=45520&edit=1



Thread (3 messages)

« previous php.bugs (#126781) next »