Skip to content

A closure that stores into its by-value captured array leaks the per-call copy (the capture param is untyped, so nothing owns the copy). #209

Closed

Description

@blacktrs

Summary

A closure that stores into its by-value captured array leaks the per-call copy (the capture param is untyped, so nothing owns the copy).

Repro

<?php
function run(string $v, int $n) {
    $seen = ['a' => 1, 'b' => 2];
    return preg_replace_callback('/x/', function ($m) use ($seen, $n) { $seen['k'] = $n; $seen['z'] = 1; return (string)count($seen); }, $v);
}
for ($i = 0; $i < 2000; $i++) { run('xx', $i); }
$base = memory_get_peak_usage();
for ($i = 0; $i < 60000; $i++) { run('xxx', $i); }
echo memory_get_peak_usage() - $base < 4 * 1024 * 1024 ? "flat\n" : "grew\n";

Expected (php)

flat

Actual (manticore c6ab7ae1, Darwin arm64)

grew

Tracking

Known-bug repro: tests/aot/repro/leak/closure_store_into_captured_array_leaks_copy.php — bash tests/aot/xfail.sh -k closure_store_into_captured_array_leaks_copy 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 12, 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