PHP是如何做垃圾回收的(图文)
zval 不存在写时复制(写时分离),会产生垃圾,PHP 的变量是使用结构体 zval 表示的 PHP 5.* zval 和 zend_value 结构 struct _zval_struct { // 结构体zvalue_value value;zend_uint refcount__gc;zend_uchar type;zend_uchar is_ref__gc;}typedef union _zvalue_value { // 联合体long lval;double dval;struct {char *val;int len;} str; // 字符串HashTable *ht; // 数组zend_object_value obj; // 对象zend_ast *ast;} zvalue_value; PHP 7.0 zval 和 zend_value 结构 struct _zval_struct {union {zend_longlval;/* long value */doubledval;/* double value */zend_refcounted *counted;zend_string*str;zend_array*arr;zend_object*obj;zend_resource *res;zend_reference *ref;zend_ast_ref*ast;zval*zv;void*ptr;zend_class_entry *ce;zend_function *func;struct {uint32_t w1;uint32_t w2;} ww;} value;union {struct {ZEND_ENDIAN_LOHI_4(zend_uchar type, PHP 7 的计数放到了具体的 value 中,可以表示整数、浮点数、字符串等类型, PHP是如何做垃圾回收的? 包含 php 5 与 php7 的变量实现和垃圾回收的对比 变量的实现 PHP 的变量是弱类型的。
我们可以理解一下 PHP 是如何做垃圾回收的了,并且放到缓冲区中 回收算法 论文:https://researcher.watson.ibm.com/researcher/files/us-bacon/Bacon01Concurrent.pdf PHP 5.3 版本以及之后的版本 1. 将垃圾放到一个 root 池中 2. 当满 10000 个节点的时候进行垃圾回收 3. 遍历双向链表中的节点 refcount-1 4. 遍历双向链表将 refcount=0 的节点删除,zend_uchar reserved)/* call info for EX(This) */} v;uint32_t type_info;} u1;union {uint32_tvar_flags;uint32_tnext;/* hash collision chain */uint32_tcache_slot;/* literal cache slot */uint32_tlineno;/* line number (for ast nodes) */uint32_tnum_args;/* arguments number for EX(This) */uint32_tfe_pos;/* foreach position */uint32_tfe_iter_idx;/* foreach iterator index */} u2;}; PHP5 与 PHP7 引用计数的对比 php 5.* 变量赋值等操作引用计数如图所示,这个会被直接清除 3. refcount 减少, 并且 PHP 7 的有一个专门的 zend_reference 用来表示引用,在倒数第二步。
并且在 unset 操作之后。
什么是垃圾 首先。
zend_uchar const_flags,/* active type */zend_uchar type_flags,我们需要定义什么是垃圾。
有了以上关于 PHP 变量存储的知识,并且 type_flag 是 IS_TYPE_COLLECTABLE 2. 没有在缓冲区中存在过 3. 没有被标记过 4. 标记为紫色,到free队列中 5. 对 refcount!=0 的 refcount 1 , 1. refcount 增加的不是 2. refcount 等于0的不是。
会形成一个循环引用,并且不等于0的才是垃圾 垃圾收集 1. php7 要求数据类型是数组和对象,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/shell/12035.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
Python2爬虫入门:正则表达
时间:2021-01-11
-
python程序的两种运行方式
时间:2021-01-11
-
Python3爬虫进阶:MySQL存储
时间:2021-01-11
-
python导入模块的关键字是
时间:2021-01-11
-
python去重函数是什么
时间:2021-01-09
-
如何用python爬虫开源项目
时间:2021-01-09
-
Photoshop设计个性笔刷制作
时间:2021-01-09
-
深入理解PHP与WEB服务器交
时间:2021-01-09
热门文章
-
解析shell字段分隔符的用法(图文)
时间:2020-12-22
-
Python3爬虫进阶:MongoDB存储(非关系型数
时间:2020-12-29
-
php如何接收json数据
时间:2021-01-08
-
php ucwords函数怎么用
时间:2021-01-08
-
如何在Linux或者UNIX下调试Bash Shell脚本
时间:2020-12-22
-
python中pow什么意思
时间:2021-01-08
-
如何在python数据挖掘使用pandas包?
时间:2021-01-09
-
关于php中匿名函数与回调函数的详解
时间:2020-12-29
-
用python以字典方式写入csv文件实现操作
时间:2021-01-07
-
easyswoole 启动TableManager Cache工具的原理
时间:2021-01-08
