The PHP garbage collector does not distinguish between the types of βthingsβ - if it has at least one link somewhere, it is saved. At a time when this is not applied, the resource collects garbage.
This is not the same as using create_function , as PHP adds the create_function link to the global scope in addition to the link to it. Closing (the Closure object, if you prefer, because that's what they are!) Exists only in the area in which it was created in + of all those with which you transmit.
If you want to make sure of this, run this little piece of code:
<?php $r = memory_get_usage(); for ($i = 0; $i < 100; $i++) { $k = function() {echo "boo"; }; if (memory_get_usage() > $r) { echo "Different memory count. Off by: ".(memory_get_usage() -$r); } $r = memory_get_usage(); }
You will receive exactly one echo. Replace the assignment of $k with create_function and you will get 100.
source share