|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-06-27 20:59 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 15 02:00:01 2025 UTC |
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.