#41830 [Opn->Bgs]: Cross referenced objects does not destroy until end of script

From: Date: Wed, 27 Jun 2007 20:59:18 +0000
Subject: #41830 [Opn->Bgs]: Cross referenced objects does not destroy until end of script
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-114358@lists.php.net to get a copy of this message
ID: 41830 Updated by: derick@php.net Reported By: rafal dot figas at posterus dot pl -Status: Open +Status: Bogus Bug Type: Unknown/Other Function Operating System: Linux Gentoo PHP Version: 5.2.3 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php That's how PHP works (For the moment) Previous Comments: ------------------------------------------------------------------------ [2007-06-27 20:45:09] rafal dot figas at posterus dot pl Description: ------------ The problem is that 2 cross referenced objects are not destroyed unless the end of script. Trying to destroy them using unset() does not work. The problem is that, if trying to analyze lots of crossed referenced objects in complex objects structure you can simply run out of the memory, and php.ini memory limits have to be very high. And I didn't find any method to reduce memory usage, to keep the script safe. The reproduce code was tested also on older version of PHP on several physical machines. This bug may be similar to #32403, but it's almost 2 years old, so I assume, the cause may be different. Reproduce code: --------------- <? class A { protected $a_napis; protected $b; function __construct(B $b) { $this->a_napis = str_repeat('Hello hell', 50000); $this->b = $b; } function __destruct() { echo "Destroying A\n"; $this->b = null; } function GetNapis() { return $this->a_napis; } function GetB() { return $this->b; } } class B { protected $b_napis; protected $a; function __construct() { $this->b_napis = str_repeat('Hello world', 1500000); } function __destruct() { echo "Destroying B\n"; $this->a = null; } function SetA($a) { $this->a = $a; } } echo "\nMemory usage at beginning: ".memory_get_usage(true); $a = new A($b = new B()); $b->SetA($a); unset($a); unset($b); echo "\nMemory usage at end: ".memory_get_usage(true); echo "\n"; ?> Expected result: ---------------- Memory usage at beginning should be equal to memory at the end. Unfortunately it is not. If u comment out the line: $b->SetA($a); everything is ok, both memory usages are equal. Destructors are called just before script ends - one can see messages echo()'ed from destructors. Actual result: -------------- The memory usages are different. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41830&edit=1

« previous php.bugs (#114358) next »