- gc_collect_cycles: documentation ( source)
- memory_get_usage: documentation ( source)
<?php
class Leak {
static protected function &leaked(array &$array = null) {
$array = array('one');
return $array;
}
public function toLeaked($array = null) {
$array = static::leaked($array);
return $array;
}
public function testLeak() {
echo "memory before loop: " . memory_get_usage() . PHP_EOL;
for ($i = 0; $i < 20000; $i++) {
$leak = $this->toLeaked();
}
gc_collect_cycles();
echo "memory after loop: " . memory_get_usage() . PHP_EOL;
}
}
$leak = new Leak();
$leak->testLeak();