Edit report at http://bugs.php.net/bug.php?id=52902&edit=1
ID: 52902 Updated by: cataphr...@php.net Reported by: jcampbell at remindermedia dot com Summary: Recursive References Leak Memory -Status: Open +Status: Bogus Type: Bug Package: Class/Object related Operating System: Fedora 12 PHP Version: 5.3.3 Block user comment: N New Comment: How is this leaking memory? Only <2MB for 2 million objects (A+B)? An object takes more than 1 byte... If you make the loop instantiate 10 times more objects, you see memory usage remains constant, so the garbage collection mechanism is definitely working here. Previous Comments: ------------------------------------------------------------------------ [2010-09-21 21:20:05] jcampbell at remindermedia dot com Description: ------------ The behavior originally reported in #33595 still exists, namely, "Objects with recursive references leak memory." Test script: --------------- class A { function __construct () { $this->b = new B($this); } } class B { function __construct ($parent = NULL) { $this->parent = $parent; } } echo memory_get_usage() . "\n"; for ($i = 0 ; $i < 1000000 ; $i++) { $a = new A(); } echo memory_get_usage() . "\n"; Expected result: ---------------- Memory usage should remain relatively constant. For example, if you change the one line to: "$this->parent = clone $parent;" Then the output is: 632216 632392 Actual result: -------------- Memory usage increases with each newly instantiated object. Actual output: 631976 1756792 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52902&edit=1