Bug #67111 [NEW]: Memory leak when using "continue 2" inside two foreach loops
| From: | thilo at eightysoft dot de | Date: | Tue, 22 Apr 2014 23:01:40 +0000 |
| Subject: | Bug #67111 [NEW]: Memory leak when using "continue 2" inside two foreach loops | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-185377@lists.php.net to get a copy of this message | ||
From: thilo at eightysoft dot de
Operating system: Debian Jessie, Linux 3.13
PHP version: 5.5.11
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Memory leak when using "continue 2" inside two foreach loops
Description:
------------
When using the short example script below, the script dies from memory
consumption going too high.
Every "continue 2" statement seems to leak 8MB of memory in this
example.
The amount of memory being leaked depends on the number of elements in
the $data array. Fewer elements --> smaller amount of memory being
leaked.
Test script:
---------------
<?php
$data=array();
for($c=0; $c<32768; $c++)
$data[$c]=array(1, 2, 3);
$filter=array(1, 2, 3);
for($kc=0; $kc<25600; $kc++)
{
$cm=memory_get_usage(true);
$pm=memory_get_peak_usage(true);
echo "<b>loop $kc: current_memory: $cm, peak_memory:
$pm...</b><br>";
flush();
foreach($data as $entry)
foreach($filter as $pattern)
continue 2;
}
?>
Expected result:
----------------
I expect to see the script running till $kc in the outer for loop
reaches 25600 and then terminate.
The consumed memory should stay (nearly?) constant throughout the script
execution.
Actual result:
--------------
loop 0: current_memory: 12582912, peak_memory: 12582912...
loop 1: current_memory: 20709376, peak_memory: 20709376...
loop 2: current_memory: 28835840, peak_memory: 28835840...
loop 3: current_memory: 36962304, peak_memory: 36962304...
loop 4: current_memory: 45088768, peak_memory: 45088768...
loop 5: current_memory: 53215232, peak_memory: 53215232...
loop 6: current_memory: 61341696, peak_memory: 61341696...
loop 7: current_memory: 69468160, peak_memory: 69468160...
loop 8: current_memory: 77594624, peak_memory: 77594624...
loop 9: current_memory: 85721088, peak_memory: 85721088...
loop 10: current_memory: 93847552, peak_memory: 93847552...
loop 11: current_memory: 101974016, peak_memory: 101974016...
loop 12: current_memory: 110100480, peak_memory: 110100480...
loop 13: current_memory: 118226944, peak_memory: 118226944...
loop 14: current_memory: 126353408, peak_memory: 126353408...
loop 15: current_memory: 134479872, peak_memory: 134479872...
loop 16: current_memory: 142606336, peak_memory: 142606336...
loop 17: current_memory: 151257088, peak_memory: 151257088...
loop 18: current_memory: 159383552, peak_memory: 159383552...
loop 19: current_memory: 167510016, peak_memory: 167510016...
loop 20: current_memory: 175636480, peak_memory: 175636480...
loop 21: current_memory: 183762944, peak_memory: 183762944...
loop 22: current_memory: 191889408, peak_memory: 191889408...
loop 23: current_memory: 200015872, peak_memory: 200015872...
loop 24: current_memory: 208142336, peak_memory: 208142336...
loop 25: current_memory: 216268800, peak_memory: 216268800...
loop 26: current_memory: 224395264, peak_memory: 224395264...
loop 27: current_memory: 232521728, peak_memory: 232521728...
loop 28: current_memory: 240648192, peak_memory: 240648192...
loop 29: current_memory: 248774656, peak_memory: 248774656...
loop 30: current_memory: 256901120, peak_memory: 256901120...
loop 31: current_memory: 265027584, peak_memory: 265027584...
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
allocate 40 bytes) in
--
Edit bug report at https://bugs.php.net/bug.php?id=67111&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67111&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67111&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67111&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67111&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67111&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67111&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67111&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67111&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67111&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67111&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67111&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67111&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67111&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67111&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67111&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67111&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67111&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67111&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67111&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67111&r=mysqlcfg