php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45520 Large memory leak when creating tree-like data structures
Submitted: 2008-07-15 13:27 UTC Modified: 2008-07-15 17:14 UTC
From: herkimer112 at yahoo dot dk Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.2.6 OS: WinXP
Private report: No CVE-ID: None
 [2008-07-15 13:27 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-15 16:27 UTC] 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 17:14 UTC] jani@php.net
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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 09:01:28 2024 UTC