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.
- gc_enable(); // Enable Garbage Collector
- var_dump(gc_enabled()); // true
- var_dump(gc_collect_cycles()); // # of elements cleaned up
- gc_disable(); // Disable Garbage Collector