Skip to content

Stdlib: gc_collect_cycles() return count — counts non-cyclic dtor as collected (Zend/zend_gc.c) #10111

Description

@PurHur

Category

stdlib · runtime · php-src-strict

Problem

gc_collect_cycles() must return the number of cyclic zvals collected in the GC run. Zend returns 0 when the only cleanup is a normal __destruct from refcount dropping to zero (no cycles). This compiler's CycleCollector::collect() returns 1 in that scenario.

php-src reference

Repro (verified 2026-06-19)

test/repro/maintainer_gap_architect_run/probe_gc_collect.php:

<?php
class C { public function __destruct() { echo "dtor\n"; } }
$a = new C();
unset($a);
echo gc_collect_cycles(), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_gap_architect_run/probe_gc_collect.php
php bin/vm.php test/repro/maintainer_gap_architect_run/probe_gc_collect.php
'
Engine Output
Zend PHP 8.x dtor then 0
VM today dtor then 1

Scope

  • lib/VM/CycleCollector.php — return count semantics
  • ext/standard/gc_collect_cycles.php — VM builtin return
  • ext/standard/GcCollectCyclesJitHelper.php / JIT path — match VM count
  • Compliance: test/compliance/cases/runtime/gc_collect_cycles_return.phpt

PHP-in-PHP: fix in CycleCollector PHP; shrink any duplicate counting in LLVM per #9269 / #10087.

Done when

  • Repro prints 0 after dtor on VM (php-src-strict)
  • True cyclic graph still returns positive count (see test/compliance/cases/runtime/gc_collect_cycles.phpt)
  • ./script/ci-fast.sh --filter gc_collect_cycles green

Related

Activity

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

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions