ID: 33595
Comment by: zwacks10 at yahoo dot com
Reported By: rodricg at sellingsource dot com
Status: Assigned
Bug Type: Class/Object related
Operating System: *
PHP Version: 6CVS-2005-08-02
Assigned To: dmitry
New Comment:
<?php
class A {
function __construct () {
$this->b = new B($this);
}
}
class B {
function __construct ($parent = NULL) {
$this->parent = $parent;
}
}
for ($i = 0 ; $i < 1000000 ; $i++) {
$a = new A();
unset($a);
}
echo number_format(memory_get_usage());
?>
Try this code. you will also avoid the memory leak...
This forum really helps me to solve this problem. You gave me an idea
to avoid this bugs. i really appreciate it. Thanks a lot guys.
Previous Comments:
------------------------------------------------------------------------
[2007-08-03 09:37:44] zwacks10 at yahoo dot com
This Forum is help full thanks to you guys.
------------------------------------------------------------------------
[2007-05-25 19:50:39] wckits at rit dot edu
Any suggestion to call the destructor explicitly is misguided at best
and dangerous at worst. You may have another reference to that object
somewhere, and it will end up being a reference to a destructed object.
------------------------------------------------------------------------
[2007-01-24 13:53:46] taneli at crasman dot fi
It shouldn't be a known "got cha".
I just wrote a backgrounded daemon using PHP and I had to instate a
checker process just to restart the process any time it dies (because it
leaks memory about 30 megs per "daemon loop", because of references).
------------------------------------------------------------------------
[2006-11-02 22:28:05] judas dot iscariote at gmail dot com
taneli at crasman dot fi :
- This is a well known "gotcha" see [1]
- for the gory details, please see [2], this is not "that easy" to
fix.
1.
http://en.wikipedia.org/wiki/Reference_counting#Advantages_and_disadvantages
2. ftp://ftp.cs.utexas.edu/pub/garbage/bigsurv.ps
------------------------------------------------------------------------
[2006-11-01 09:07:48] taneli at crasman dot fi
Please address this bug, it's very short-sighted to rely on the fact
that memory is freed on shutdown (especially when your either your box
starts trashing or memory_limit kicks in and fails your request because
of a bug in the interpreter).
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/33595
--
Edit this bug report at http://bugs.php.net/?id=33595&edit=1