ID: 33595 Comment by: K dot Londenberg at librics dot de 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:
The problem with circular references is a known weakness of reference counting schemes. Python uses a workaround (cycle detector). Excerpt from http://wingware.com/psupport/python-manual/2.4/ext/refcounts.html: " While Python uses the traditional reference counting implementation, it also offers a cycle detector that works to detect reference cycles. This allows applications to not worry about creating direct or indirect circular references; these are the weakness of garbage collection implemented using only reference counting. Reference cycles consist of objects which contain (possibly indirect) references to themselves, so that each object in the cycle has a reference count which is non-zero. Typical reference counting implementations are not able to reclaim the memory belonging to any objects in a reference cycle, or referenced from the objects in the cycle, even though there are no further references to the cycle itself. " Maybe this would also be a viable Strategy for PHP.. Previous Comments: ------------------------------------------------------------------------ [2006-01-19 10:31:05] letssurf at gmail dot com Thank you for your solution. It's the same path we had taken here. We had created a kill() method to do the same job. Shame it hasn't been fixed. Thank you again :) ------------------------------------------------------------------------ [2006-01-17 19:08:55] rodricg at sellingsource dot com You can avoid the memory leak by manually calling the destructors and unsetting the recursive ref: <?php class A { function __construct () { $this->b = new B($this); } function __destruct () { $this->b->__destruct(); } } class B { function __construct ($parent = NULL) { $this->parent = $parent; } function __destruct () { unset($this->parent); } } for ($i = 0 ; $i < 1000000 ; $i++) { $a = new A(); $a->__destruct(); } echo number_format(memory_get_usage()); ?> ------------------------------------------------------------------------ [2006-01-17 17:56:50] letssurf at gmail dot com I agree this is a very annoying bug for large scale projects and should be fixed or noted in the manual. What is the best work around for this bug? ------------------------------------------------------------------------ [2005-12-05 08:40:36] marek at lewczuk dot com The bug still exists in 5.1.1. If this cannot be solved in near future then I think it should be noted somewhere in the manual. ------------------------------------------------------------------------ [2005-08-01 11:00:32] [EMAIL PROTECTED] Yes. This is different bug. However it is not very critical (as bug #33487 too), because all memory is freed on request shutdown. I don't know how to implement support for circular data structures freeing without significant performance lose. ------------------------------------------------------------------------ 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
