If: the cycle will work for a very long time; you expect a large number of concurrent users; or the server has limited resources (for example, the host itself, VPS / shared, etc.), then you do not need to worry about it. In any case, when the script will not work for a very long time (less than 5 seconds), everything you try to do to free memory will be less efficient than the PHP garbage collector.
However, if you need to clear the link (due to one of the above scenarios or because you like being careful), you can set the variable to null or use the unset function. This will remove the link, and the PHP garbage collector will clear it because there are no more links to it.
source share