echo " --- in anon function ----" . PHP_EOL; _mem(); echo " -------------------------" . PHP_EOL; }; _mem(); _step("Anon function call"); $anon(); _mem(); $anonAlias = $anon; _step("Anon function call again via alias"); $anonAlias(); _mem(); _step("Anon function remove"); unset($anon); _mem(); _step("Anon function alias remove"); unset($anonAlias); _mem(); $loop = 5; for ($i = 1; $i <= $loop; $i++) { _step("Loop [{$i}/{$loop}] anon function define"); $anon = function () { static $static = 0; $static = _data(1); $dynamic = _data(1); }; _mem(); _step("Loop [{$i}/{$loop}] anon function call [loop]"); $anon(); _mem(); }
for ($i = 0; $i < 100; $i++) { $all[] = $data; _mem(); } _mem(); _var('data'); _step("Pass string value to read"); dataSize($data); _mem(); _var('data'); _step("Pass array value to read"); dataSize($all); _mem(); _var('all'); _step("Pass string value to change"); changeValueOf($data); _mem(); _var('data'); _step("Pass array value to change"); changeValueOf($all); _mem(); _var('all'); // passing by reference to immutable values uses more memory in this case! _step("Pass string reference to change"); changeValueOfReference($data); _mem(); _var('data'); _step("Pass array reference to change"); changeValueOfReference($all); _mem(); _var('all');
require_once 'lib.php'; _step("GC Cyclic Start!"); _mem(); _step("Bruce come"); $someData = _data(); $bruce = new User('bruce', '1960-12-26'); $bruce->store($someData); _mem(); _var('someData'); _var('bruce'); _step("Robin come and talk to bruce"); $robin = new User('robin', '1970-10-14'); $robin->store($someData); $bruce->talk($robin); $robin->talk($bruce); _mem(); _var('someData'); _var('bruce'); _var('robin'); _step("Clear all"); unset($robin); unset($bruce); unset($someData); _mem(); _var('someData'); _var('bruce'); _var('robin'); _step("Collecting cycles"); gc_collect_cycles(); _mem();
_mem(); _step("Robin come"); $robin = new User('robin', '1970-10-14'); $robin->store($someData); $bruce->talk($robin); _mem(); _var('someData'); _var('bruce'); _var('robin'); _step("Robin go"); unset($robin); _mem(); _var('someData'); _var('bruce'); _var('robin'); _step("Big string go"); unset($someData); _mem(); _var('someData'); _var('bruce'); _var('robin'); _step("Bruce new pocket"); $bruce->store('OK'); _mem(); _var('bruce'); _step("Bruce go"); unset($bruce); _mem(); _var('someData'); _var('bruce'); _var('robin');