PHP是如何做垃圾回收的?
包含 php 5 与 php7 的变量实现和垃圾回收的对比
变量的实现
PHP 的变量是弱类型的,可以表示整数、浮点数、字符串等类型。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_long lval; /* long value */ double dval; /* 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, /* active type */ zend_uchar type_flags, zend_uchar const_flags, 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; };
以上就是PHP是如何做垃圾回收的(图文)的详细内容,更多请关注Gxlcms其它相关文章!
查看更多关于PHP是如何做垃圾回收的(图文)的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did55977