Bug #71297 [NEW]: Memory leak with yield from
From: karl dot malakoff at dataprocessors dot com dot au
Operating system: Windows 7
PHP version: 7.0.1
Package: Reproducible crash
Bug Type: Bug
Bug description:Memory leak with yield from
Description:
------------
I've found a memory leak that occurs when iterating over a generator
that directly yields from another generator inside a loop (see
genLeak()).
It seems that this can be worked around by assigning the result of the
yield from to a temp var and then yielding that var (see genNoLeak()).
Directly yielding is also fine (see gen()).
Test script:
---------------
<?php
function foo()
{
yield array_fill(0, 10000, 4);
}
function gen()
{
while(true){
yield array_fill(0, 10000, 4);
print memory_get_usage(false).PHP_EOL;
}
}
function genLeak()
{
while(true){
yield from foo();
print memory_get_usage(false).PHP_EOL;
}
}
function genNoLeak()
{
while(true){
$tmp = yield from foo();
yield $tmp;
print memory_get_usage(false).PHP_EOL;
}
}
foreach(genLeak() as $i){}
Expected result:
----------------
Memory usage remains constant though each iteration of the loop.
Actual result:
--------------
Memory usage rises until php runs out of memory and crashes.
--
Edit bug report at https://bugs.php.net/bug.php?id=71297&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71297&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71297&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71297&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71297&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71297&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71297&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71297&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71297&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71297&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71297&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71297&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71297&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71297&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71297&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71297&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71297&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71297&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71297&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71297&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71297&r=mysqlcfg
Thread (2 messages)
- karl dot malakoff at dataprocessors dot com dot au