3v4l.org

run code in 200+ PHP versions simultaneously
<?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;
based on XIQhR
Output for 7.3.0 - 7.3.1
Test empty object memory leakage test 1 int(392464) int(392464) test 2 int(392464) int(400656) test 3 int(400656) int(417040) test 4 int(417040) int(417040)
Output for 7.2.0 - 7.2.13
Test empty object memory leakage test 1 int(388568) int(388568) test 2 int(388568) int(396760) test 3 int(396760) int(413144) test 4 int(413144) int(413144)
Output for 7.1.25
Test empty object memory leakage test 1 int(351960) int(351960) test 2 int(351960) int(360152) test 3 int(360152) int(376536) test 4 int(376536) int(376536)
Output for 7.1.0 - 7.1.1, 7.1.7 - 7.1.22
Test empty object memory leakage test 1 int(352032) int(352032) test 2 int(352032) int(360224) test 3 int(360224) int(376608) test 4 int(376608) int(376608)
Output for 7.1.2 - 7.1.6
Test empty object memory leakage test 1 int(352328) int(352328) test 2 int(352328) int(360520) test 3 int(360520) int(376904) test 4 int(376904) int(376904)
Output for 5.6.30
Test empty object memory leakage test 1 int(227440) int(227472) test 2 int(227472) int(293008) test 3 int(293008) int(424080) test 4 int(424080) int(424080)