PHP garbage collection is largely a reference counter. If you are keeping references which are still accessible around these will easily add up if not freed. PHP has built-in function to manage that garbage collection or memory cleanup for long-running scripts. these php functions can easily improve your site performance. Below is the php script for garbage collection that’s surely work for you.