Skip to content

A property read on an ArrayAccess offsetGet result ($o[$k]->p) never releases the returned object. #132

Closed

Description

@blacktrs

Summary

A property read on an ArrayAccess offsetGet result ($o[$k]->p) never releases the returned object.

Repro

<?php
final class Box { public function __construct(public string $s) {} }
final class C implements ArrayAccess {
    private array $d = [];
    public function offsetExists(mixed $o): bool { return isset($this->d[$o]); }
    public function offsetGet(mixed $o): mixed { return $this->d[$o]; }
    public function offsetSet(mixed $o, mixed $v): void { $this->d[$o] = $v; }
    public function offsetUnset(mixed $o): void { unset($this->d[$o]); }
}
function churn(int $n): int
{
    $b = new C();
    $len = 0;
    for ($i = 0; $i < $n; $i++) { $b[$i & 127] = new Box('c'); $len += strlen($b[$i & 127]->s); }
    return $len;
}
churn(2000);
$before = memory_get_peak_usage();
churn(200000);
echo memory_get_peak_usage() - $before < 2 << 20 ? "flat\n" : "grows\n";

Expected (php)

flat

Actual (manticore f0715b20, Darwin arm64)

grows

Tracking

Known-bug repro: tests/aot/repro/leak/arrayaccess_offsetget_property_base_leaks.php — bash tests/aot/xfail.sh -k arrayaccess_offsetget_property_base_leaks 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 7, 2026
  2. blacktrs commented on Oct 7, 2026

    @blacktrs
    ContributorAuthor

    Same root, second shape: $x = $o[$k]; on any ArrayAccess object leaks too — the offsetGet call hands out +1 and the store-local element-read co-own (EmitLlvmLocals::elemReadCoOwn) retains it again, because the ArrayAccess_ node is read as a BORROW. Manticore\Ds\Map [] reads with a typed key no longer hit it (the inline fast path hands out a real borrow); every other ArrayAccess class does.

  3. added 2 commits that reference this issue on Oct 8, 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