ID: 45520
Comment by: crrodriguez at suse dot de
Reported By: herkimer112 at yahoo dot dk
Status: Open
Bug Type: Performance problem
Operating System: WinXP
PHP Version: 5.2.6
New Comment:
There is no memory leak, memory is freed at script shutdown /by, looks
like the expected "by-design" behaviour.
Previous Comments:
------------------------------------------------------------------------
[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