|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-07-15 16:27 UTC] crrodriguez at suse dot de
[2008-07-15 17:14 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 06:00:01 2025 UTC |
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