#33595 [Com]: recursive references leak memory

From: Date: Thu, 22 Nov 2007 14:48:30 +0000
Subject: #33595 [Com]: recursive references leak memory
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-119956@lists.php.net to get a copy of this message
ID: 33595 Comment by: shez at starfangled dot net 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: Hi, Does anybody have an easy way to trace _what_ objects have been leaked due to circular references? I've had couple of cases in large code bases that I've had to trace by the old binary search algorithm (you know the one, remove half of the code, test, etc ;) Cheers! Shez Previous Comments: ------------------------------------------------------------------------ [2007-08-04 00:40:21] zwacks10 at yahoo dot com <?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. ------------------------------------------------------------------------ [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 ------------------------------------------------------------------------ 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

« previous php.bugs (#119956) next »