gc_status
(PHP 7 >= 7.3.0)
gc_status — ガベージコレクタに関する情報を取得する
説明
gc_status ( ) : array
ガベージコレクタの現在の状態に関する情報を取得します。
パラメータ
この関数にはパラメータはありません。
返り値
次の要素を持つ連想配列を返します:
-
"runs"
-
"collected"
-
"threshold"
-
"roots"
例
例1 gc_status() の使い方
<?php// create object tree that needs gc collection$a = new stdClass();$a->b = [];for ($i = 0; $i < 100000; $i++) { $b = new stdClass(); $b->a = $a; $a->b[] = $b;}unset($a);unset($b);gc_collect_cycles();var_dump(gc_status());
上の例の出力は、 たとえば以下のようになります。
array(4) { ["runs"]=> int(5) ["collected"]=> int(100002) ["threshold"]=> int(50001) ["roots"]=> int(0) }