Bug #71297 [Opn->Csd]: Memory leak with yield from

From: Date: Thu, 07 Jan 2016 10:56:36 +0000
Subject: Bug #71297 [Opn->Csd]: Memory leak with yield from
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198484@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71297&edit=1

 ID:                 71297
 Updated by:         bwoebi@php.net
 Reported by:        karl dot malakoff at dataprocessors dot com dot au
 Summary:            Memory leak with yield from
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Reproducible crash
 Operating System:   Windows 7
 PHP Version:        7.0.1
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=033d6087711332efab4fbb1cb90acabd9af8534b
Log: Fixed bug #71297 (Memory leak with yield from)


Previous Comments:
------------------------------------------------------------------------
[2016-01-07 02:13:41] karl dot malakoff at dataprocessors dot com dot au

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 this bug report at https://bugs.php.net/bug.php?id=71297&edit=1


Thread (2 messages)

« previous php.bugs (#198484) next »