<?php
class NonLeakingClass
{
protected $x=[1,2,3,4,5,6,7,8,9,10];
public function __counstruct(){
}
}
class NonLeakingClass2
{
protected $x=[1,2,3,4,5,6,7,8,9,10];
public function __counstruct(){
}
}
function test($x){
$ret = [];
for($i=0;$i<(1022/2)*$x;$i++){
$ret[] = new NonLeakingClass();
$ret[] = new NonLeakingClass2();
}
return $ret;
}
echo "Test empty object memory leakage" . PHP_EOL; // WARNING: Uncomment this line and PHP stops to leak memory on object creation, strange :)
for ($h = 1; $h < 5; $h++) {
echo "test $h \n\n";
var_dump(memory_get_usage(false));
$a = test($h);
unset($a);
gc_collect_cycles();
var_dump(memory_get_usage(false));
}
exit;
preferences:
34.76 ms | 402 KiB | 5 Q