gc

本文最后更新于:2023年12月5日 晚上

数组初始化$arr = [1,2,3];,打印 gc 发现 refcount=2;

数组初始化$arr = ['time'=>time()];, 打印 gc 发现 refcount=1;

这是为什么呢?

这牵扯到 PHP7 中的另一个概念,叫做 immutable array (不可变数组),在不可变数组下,使用一个伪计数值 2。类型是这种直接申明规定数组

摘抄一段 PHP7 数组开发成员的一段原话:

For arrays the not-refcounted variant is called an “immutable array”. If you use opcache, then constant array literals in your code will be converted into immutable arrays. Once again, these live in shared memory and as such must not use refcounting. Immutable arrays have a dummy refcount of 2, as it allows us to optimize certain separation paths.


gc
http://blog.lujinkai.cn/PHP/源码/gc/
作者
像方便面一样的男子
发布于
2020年12月9日
更新于
2023年12月5日
许可协议