From: thomas dot jarosch at intra2net dot com
Operating system: Linux
PHP version: 5.3CVS-2008-06-04 (snap)
PHP Bug Type: Reproducible crash
Bug description: garbage collector and cyclic references
Description:
------------
Hello together,
I'm currently trying to find a heap corruption while using Horde and
noticed a rather odd behavior. The supplied code is the standard way
Horde does it singletons. We always used the syntax of "$object =
&new class" to make it work with PHP4 and PHP5.
If I change that to "$object = new class", everything works as
expected. I've found bug #32845 and noticed what we are doing seems
wrong, so Horde needs fixing.
The problem gets worse if the class object contains a variable of the
type "PEAR_Error", which contains cyclic references. Not only does
the constructor get called every time, the object leaks memory like
hell, even with PHP 5.3. I've searched through the bugtracker and
thought the garbage collector now handles cyclic references,
but maybe this is a side-effect of something else going wrong.
Is the memory consumption by design?
Thanks in advance for any comment,
Thomas
Reproduce code:
---------------
<?php
require_once "PEAR.php";
class Horde_History
{
var $error;
function &singleton()
{
static $history;
if (!isset($history)) {
$history = &new Horde_History();
}
return $history;
}
function Horde_History()
{
$this->error = PEAR::raiseError("error");
echo "Memory usage: " . memory_get_usage() . "\n";
}
}
for (;;) {
$a = Horde_History::singleton();
}
Expected result:
----------------
Constant memory usage.
Actual result:
--------------
Increasing memory usage.
--
Edit bug report at http://bugs.php.net/?id=45178&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=45178&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=45178&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=45178&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=45178&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=45178&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=45178&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=45178&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=45178&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=45178&r=support
Expected behavior: http://bugs.php.net/fix.php?id=45178&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=45178&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=45178&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=45178&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45178&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=45178&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=45178&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=45178&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=45178&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=45178&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=45178&r=mysqlcfg