Skip to content

Commit

Permalink
php的垃圾回收机制
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexchent committed Jul 4, 2021
1 parent 5fcbed5 commit 3026acf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Memory/gc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php/** * php的垃圾挥手机制gc * * 5.3版本之后: * 每个php变量存在一个叫"zval"的变量容器中。一个zval变量容器,除了包含变量的类型和值,还包括两个字节的额外信息。 * 第一个是"is_ref",是个bool值,用来标识这个变量是否是属于引用集合(reference set)。通过这个字节,php引擎才能把普通变量和引用变量区分开来,由于php允许用户通过使用&来使用自定义引用, * zval变量容器中还有一个内部引用计数机制,来优化内存使用。 * * 第二个额外字节是"refcount",用以表示指向这个zval变量容器的变量(也称符号即symbol)个数。所有的符号存在一个符号表中,其中每个符号都有作用域(scope)。 * refcount归零是回收对应的内存 * * PHP7版本之后: * zval可以被引用计数或不被引用。在zval结构中有一个标志确定了这一点。 * 1. 对于null,bool,int和double的类型变量,refcount永远不会计数; * 2. 对于对象、资源型,refcount和之前的版本一致 * 3. 对于字符串,未被引用的字符串被称为"实际字符串",不需要就计数。 * 4. 对于数组,未被引用的数组被称为"不可变数组"。其数组本身的计数器与之前的版本一致。但数组内的键值对的计数,按前前面的数据类型规则。 *///xdebug_debug_zval 需要安装debug扩展//测试echo "测试字符串引用计数".PHP_EOL;$a = "new string";$b = $a;xdebug_debug_zval('a');unset($b);xdebug_debug_zval('a');
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@
4. 中介者模式
5. 观察者模式!!
6. 状态模式 用多个状态类代替if-else
7. 策略模式
7. 策略模式
8. 模板模式 简单说就是继承
9. 访问者模式
10. 备忘录模式
11. 空对象模式

## [Swoole客户端&服务端](/Swoole)
1. 启动服务端
Expand Down

0 comments on commit 3026acf

Please sign in to comment.