There is hardly a reason for this. All memory will be freed when the script completes.
But if you allocate a lot of memory, this can be useful, especially if your scripts take a little longer to run. The memory will be freed immediately and can be used by other scripts.
But, as you say, this requires code, which makes your code less clear. Therefore, do this only if you have allocated large chunks of data that you no longer need, for example, the contents of a file read from disk or large arrays with query results. Don't let go of integers and don't worry about the message line. :)
{edit after comments}
My answer was mainly focused on using PHP for web scripts. Of course, if you create long scripts, especially if the amount of memory that they allocate is very variable, then of course it makes sense to free up memory, although even these scripts work for a limited period of time.
I do not think that in PHP there are many demons that work forever. Most scripts, even those shell scripts, perform a specific task (if you can call "website rendering" or "database migration"), after which they end. In the context of this task, it is still completely useless to free every variable that you have allocated. This is very different from scripts like these and programs that can run for a long time, perform the same task again and again, or are completely controlled by the user, so you donβt know what they will do. And if you manage to write a long script or daemon in PHP, other rules apply because it is a different kind of application. But by then you will not be looking for this answer, because you have already received more than enough knowledge to know what you are doing.
source share