Skip to content

A cycle collected by gc_collect_cycles() never runs __destruct on its objects (php runs it during the collection). #118

Closed

Description

@blacktrs

Summary

A cycle collected by gc_collect_cycles() never runs __destruct on its objects (php runs it during the collection).

Repro

<?php
final class Node { public ?Node $next = null; public function __construct(public string $name) {} public function __destruct() { echo "destruct {$this->name}\n"; } }
function make(): void { $a = new Node('a'); $b = new Node('b'); $a->next = $b; $b->next = $a; }
make();
echo "before gc\n";
echo gc_collect_cycles() > 0 ? "collected\n" : "nothing\n";
echo "after gc\n";

Expected (php)

before gc
destruct a
destruct b
collected
after gc

Actual (manticore 46bda0f8, Darwin arm64)

before gc
collected
after gc

Tracking

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

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

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions