Skip to main content

PHP Garbage Collection

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.

  1. <?php
  2. gc_enable(); // Enable Garbage Collector
  3. var_dump(gc_enabled()); // true
  4. var_dump(gc_collect_cycles()); // # of elements cleaned up
  5. gc_disable(); // Disable Garbage Collector
  6. ?>

PHPZAG.COM is a popular PHP tutorial blog that publishes useful tips and tutorials for PHP programmer. If you would like to be kept up to date with our posts, you can subscribe to our RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *


Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!