I often find references to the following quote being used when explaining that a PHP unset()
doesn't trigger "garbage collection" immediately, but only when it sees fit (emphasis mine):
unset() does just what it's name says
- unset a variable. It does not force immediate memory freeing. PHP's garbage collector will do it when it see fits - by intention as soon, as those CPU cycles aren't needed anyway, or as late as before the script would run out of memory, whatever occurs first.
If you are doing $whatever = null; then you are rewriting variable's data. You might get memory freed / shrunk faster, but it may steal CPU cycles from the code that truly needs them sooner, resulting in a longer overall execution time.
I want to know how the C code for this "low memory" and "free CPU cycles" triggering of the garbage collection works exactly and whether it differs between PHP 5.2.x and PHP 5.3+.
So I downloaded the C source files of PHP 5.2.17 and tried to locate the proper code sections. Maybe I'm just blind, or my C skills are too low, but I failed to find such code.
Can somebody point me to the proper C files, please?
EDIT:
While searching for example usages of the above quote, I realized something weird.
Some of the examples, like https://mcmap.net/q/108690/-what-39-s-better-at-freeing-memory-with-php-unset-or-var-null, reference to this quote by using the following URL to a comment on php.net: https://www.php.net/manual/en/function.unset.php#86347.
Browsing to this URL only shows the top of the unset()
manual. Comment #86347 is missing.
Checking the wayback machine shows, that this comment DID exist from Oct 2008, but vanished sometime in or after Sep 2012 (reason unknown).
Maybe that quote is, and always was, just plain wrong?
Or is there anybody out there, who can point me to the proper C files?