#46790 [NEW]: Memory leak with classes
| From: | o_O_Tync at mail dot ru | Date: | Sun, 07 Dec 2008 06:34:04 +0000 |
| Subject: | #46790 [NEW]: Memory leak with classes | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-131705@lists.php.net to get a copy of this message | ||
From: o_O_Tync at mail dot ru
Operating system: Win, FreeBSD
PHP version: 5.2.7
PHP Bug Type: Class/Object related
Bug description: Memory leak with classes
Description:
------------
I've come across a memory leak: garbage collector failes to free memory
occupied by linked objects, such as:
$obj1->pair = $obj2; $obj2->pair = $obj1;
Below goes the problematic piece of code: over many iterations - it
occupies a lot of memory.
If we comment 'line1' or 'line2' or both - memory is okay (48 Kb), but
cross-linking reveals a bug (839 Kb) despite of explicit unsetting.
The commented 'this helps' line solves the problem.
Tested under WinXP, and FreeBSD 6.1 using the latest PHP 5.2.7
Reproduce code:
---------------
<?php
class Paired
{
/** Paired object
* @var Paired
*/
public $pair;
}
for ($i=0;$i<2000;$i++)
{
$obj1 = new Paired; $obj2 = new Paired;
$obj1->pair = $obj2; // 'line1'
$obj2->pair = $obj1; // 'line2'
// $obj1->pair = null; $obj2->pair = null; // this helps
unset($obj1); unset($obj2); // Explicitly
}
print 'Mem: '.floor(memory_get_usage()/1024).' Kb';
?>
Expected result:
----------------
Mem: 48 Kb
Actual result:
--------------
Mem: 839 Kb
--
Edit bug report at http://bugs.php.net/?id=46790&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46790&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46790&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46790&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46790&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46790&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=46790&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46790&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46790&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46790&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46790&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46790&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=46790&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=46790&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46790&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46790&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46790&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46790&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46790&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46790&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46790&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46790&r=mysqlcfg