Skip to content

Leak: every heap value a generator yields into a foreach is never released #23

Closed

Description

@blacktrs

Summary

Leak: every heap value a generator yields into a foreach is never released.

Fix planned in the ownership redesign epic (PR #15, task 10: generator frames). Tracking only.

Repro

<?php
final class M { public function __construct(public readonly string $data) {} }
function gObj(int $n): \Generator { for ($i = 0; $i < $n; $i++) { yield new M(str_repeat('x', 100) . $i); } }
function gStr(int $n): \Generator { for ($i = 0; $i < $n; $i++) { yield str_repeat('x', 100) . $i; } }
$m0 = memory_get_peak_usage();
foreach (gObj(100000) as $v) { $d = $v->data; }
foreach (gStr(100000) as $v) { }
$mb = (memory_get_peak_usage() - $m0) >> 20;
fwrite(STDERR, "grew {$mb} MB\n");
echo $mb < 8 ? "flat\n" : "LEAK\n";

The repro measures its own peak RSS (memory_get_peak_usage()) around the loop and prints flat when it grew by less than 8 MB.

Expected (php 8.5)

flat

Actual (manticore 10affa68, macOS arm64)

LEAK
(stderr: grew 33 MB)

Tracking

Known-bug repro: tests/aot/repro/leak/generator_yield.php — bash tests/aot/xfail.sh -k generator_yield reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    leak
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugleak

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions