Preface: I do know how 'unset' works in the userland, but I would like to find out how it works internally.
When unset is called on zval structure, it decreases the reference counter (refcount__gc). When refcount__gc reaches 0, the variable is no longer used and can be deleted. The question is whether it's always done immediately, or in some cases it can be done later by garbage collector?
I have found two contradictory statements on this:
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. - Stackoverflow answer mentioning 2009 php.net documentation
And the opposite:
When the refcount hits zero, the zval is destroyed and any memory that it was holding is now free - Better Understanding PHP’s Garbage Collection, 2012 article
So which one is correct as of let's say PHP 5.3 and PHP 5.5? If possible, maybe you can provide a link to the unset definition in the PHP source code. Thank you!