かんぱーい
tested on php 7.4
インターン化
同じ文字列を共通領域に保管してメモリ使用量を節約する
参照カウンタを使ってる
name: (interned, is_ref=0)='@ariaki4dev'
hello: (refcount=1, is_ref=0)='Hello, @ariaki4dev'
hoge: (refcount=2, is_ref=0)=array (0 => (refcount=1, is_ref=0)='php')
fuga: (refcount=1, is_ref=0)=array (0 => (interned, is_ref=0)='php')
hoge: (interned, is_ref=0)='@ariaki4dev'
fuga: (refcount=0, is_ref=0)=1234
piyo: (refcount=2, is_ref=0)=array
(0 => (refcount=1, is_ref=0)='php',
1 => (refcount=1, is_ref=0)='conference',
2 => (refcount=0, is_ref=0)=2020)
→ 0
→ 80
name: (interned, is_ref=0)='@ariaki4dev'
name: (refcount=2, is_ref=1)='@ariaki4dev'
nick: (refcount=2, is_ref=1)='@ariaki4dev'
nick: (refcount=1, is_ref=1)='@ariaki4dev'
$name
$nick
コピーオンライト
オブジェクトがコピーされた時点ではメモリを確保せず、
変更が必要な時点になってはじめてメモリを確保する。
→ 0
→ 32
→ 408
→ 32
GCの挙動
→ 864
→ 864
→ 32
→ 80
→ 1280
→ 352
→ 352
→ 80
PHP 7.4〜
GCの挙動
↓更に詳しくはこちら↓