3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MemoryLeak { public function bad() { $closure = function ($this) {}; $closure([$this]); } public function good1() { $closure = function ($param) {}; $closure([$this]); } public function good2() { $closure = function ($this) {}; $closure($this); } } $object = new MemoryLeak; $usage = 0; ini_set('memory_limit', '10M'); for ($i = 0; $i < 1000000; ++$i) { $object->bad(); } echo "Done" . PHP_EOL;

preferences:
23.55 ms | 404 KiB | 5 Q