php / php/php-src

Ref counting based object release is not applied if cycle is broken in destructor during GC run

未关闭
#13,683 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Category: GC Status: Needs Triage
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

Description

repro: https://3v4l.org/USrWu

see UPDATE below

It seems the GC can be improved. Currently, when a cycle is broken during GC run, a 2nd run of GC is needed to really release the object.

https://github.com/php/php-src/commit/b58d74547f "solves this issue" since PHP 8.2+, but is that the most efficient solution for everything? If a cycle (all cycles/references to an object) is explicitly broken during GC, is there anything againts releasing that object by standard refcounting?

Resulted in this output:

d
gc
bool(true) <- notice object is kept alive after the destructor has broken the cycle (and refcount dropped to 0)
gc rerun
bool(false)
bool(false)
done

But I expected this output instead:

d
gc
bool(false)
gc rerun
bool(false)
bool(false)
done

UPDATE:

Based on https://3v4l.org/mgoqd I would call this a bug as 2nd WeakReference::get() call is expected to always give the same result if no GC is run in between the calls.

PHP Version

any (tested PHP 7.4, 8.3)

Operating System

any

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先运行 https://3v4l.org/USrWu 中的复现,并将其与 https://3v4l.org/mgoqd 中更新后的示例进行比较,重点关注 GC、析构函数、引用计数和 WeakReference::get()。当在一次 GC 运行期间断开的循环能够立即释放对象,使两个 WeakReference 检查都与预期输出一致且无需第二次运行 GC 时,即可视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
c
领域
backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。