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; } 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 lV6mL
Output for 7.2.11
test 1 int(388504) int(388504) test 2 int(388504) int(396696) test 3 int(396696) int(413080) test 4 int(413080) int(413080)
Output for 7.2.0 - 7.2.10
test 1 int(388544) int(388544) test 2 int(388544) int(396736) test 3 int(396736) int(413120) test 4 int(413120) int(413120)
Output for 7.1.23
test 1 int(351896) int(351896) test 2 int(351896) int(360088) test 3 int(360088) int(376472) test 4 int(376472) int(376472)
Output for 7.1.0 - 7.1.1, 7.1.7 - 7.1.22
test 1 int(351968) int(351968) test 2 int(351968) int(360160) test 3 int(360160) int(376544) test 4 int(376544) int(376544)
Output for 7.1.2 - 7.1.6
test 1 int(352264) int(352264) test 2 int(352264) int(360456) test 3 int(360456) int(376840) test 4 int(376840) int(376840)
Output for 7.0.0 - 7.0.31
test 1 int(351928) int(351928) test 2 int(351928) int(360120) test 3 int(360120) int(376504) test 4 int(376504) int(376504)
Output for 5.6.0 - 5.6.29, 5.6.31 - 5.6.38
test 1 int(227080) int(227112) test 2 int(227112) int(292648) test 3 int(292648) int(423720) test 4 int(423720) int(423720)
Output for 5.6.30
test 1 int(227264) int(227296) test 2 int(227296) int(292832) test 3 int(292832) int(423904) test 4 int(423904) int(423904)
Output for 5.5.0 - 5.5.38
test 1 int(227032) int(227040) test 2 int(227040) int(292576) test 3 int(292576) int(423648) test 4 int(423648) int(423648)
Output for 5.4.0 - 5.4.45
test 1 int(227512) int(227544) test 2 int(227544) int(293080) test 3 int(293080) int(424152) test 4 int(424152) int(424152)
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/5ap4Z on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/5ap4Z on line 5
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/5ap4Z on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/5ap4Z on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/5ap4Z on line 5
Process exited with code 255.