ID: 33595 Comment by: letssurf at gmail 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:
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 :) Previous Comments: ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ [2005-07-07 03:49:52] rodricg at sellingsource dot com Distinctly different than bug #33487 this only occurs when the object contains a recursive reference. Add echo number_format(memory_get_usage()); to the end of the script and you get 346,360,656. Then comment out $this->parent = $parent and run again to get 53,832. I suspect the internal reference is not properly invalidated upon the destruction of class A. This would keep the ref count > 0 and foil garbage collection. Unless I am missing something.... ------------------------------------------------------------------------ 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