From: soywiz at gmail dot com Operating system: General PHP version: 5.2.8 PHP Bug Type: Scripting Engine problem Bug description: memory leak using foreach and references
Description:
------------
This snippet causes an out of memory. It seems that it's duplicating the
value (it's trying to allocate a memory chunk as large as each element on
the array) and it's not freeing it.
The problem persists even with a unset($v); within the foreach.
I reproduced it using php 5.2.8-cli on windows and php 5.2.5-cgi on
linux.
I think it should work, but maybe it's a php feature?
Reproduce code:
---------------
<?php
$a = array_fill(0, 99999, str_repeat('*', 9991));
foreach ($a as &$v) ;
?>
Expected result:
----------------
Don't waste all the memory
Actual result:
--------------
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to
allocate 9992 bytes) in test.php on line 3
--
Edit bug report at http://bugs.php.net/?id=47103&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47103&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47103&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47103&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47103&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47103&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47103&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47103&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47103&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47103&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47103&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47103&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47103&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47103&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47103&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47103&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47103&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47103&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47103&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47103&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47103&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47103&r=mysqlcfg
