#41830 [NEW]: Cross referenced objects does not destroy until end of script
| From: | rafal dot figas at posterus dot pl | Date: | Wed, 27 Jun 2007 20:45:10 +0000 |
| Subject: | #41830 [NEW]: Cross referenced objects does not destroy until end of script | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-114355@lists.php.net to get a copy of this message | ||
From: rafal dot figas at posterus dot pl
Operating system: Linux Gentoo
PHP version: 5.2.3
PHP Bug Type: Unknown/Other Function
Bug description: Cross referenced objects does not destroy until end of script
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 bug report at http://bugs.php.net/?id=41830&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41830&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41830&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41830&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41830&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=41830&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41830&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41830&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41830&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41830&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41830&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=41830&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=41830&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41830&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41830&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41830&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41830&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41830&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41830&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41830&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41830&r=mysqlcfg