| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2016-01-07 10:56 UTC] bwoebi@php.net
  [2016-01-07 10:56 UTC] bwoebi@php.net
 
-Status: Open
+Status: Closed
  [2016-01-07 10:57 UTC] bwoebi@php.net
  [2016-07-20 11:34 UTC] davey@php.net
  | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 02:00:01 2025 UTC | 
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.