- ini_set: documentation ( source)
<?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;