Bug #52902 [Com]: Recursive References Leak Memory
| From: | jcampbell at remindermedia dot com | Date: | Tue, 21 Sep 2010 19:57:29 +0000 |
| Subject: | Bug #52902 [Com]: Recursive References Leak Memory | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-154541@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52902&edit=1
ID: 52902
Comment by: jcampbell at remindermedia dot com
Reported by: jcampbell at remindermedia dot com
Summary: Recursive References Leak Memory
Status: Bogus
Type: Bug
Package: Class/Object related
Operating System: Fedora 12
PHP Version: 5.3.3
Block user comment: N
New Comment:
You're correct that it does form a cycle of memory usage going up and
then back down. However, when using cloned objects, the memory usage is
exactly the same after every loop.
So if you make the objects larger so that a bunch of them don't fit
under the memory limit but one does, then you'll run out of memory.
Again, using cloned objects, you can loop indefinitely.
Is the solution to this to manually run gc_collect_cycles() when dealing
with large objects? Because that workaround does seem to have the same
effect on memory as cloning.
Previous Comments:
------------------------------------------------------------------------
[2010-09-21 21:32:10] cataphract@php.net
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.
------------------------------------------------------------------------
[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