od2uca
Last Updated: February 25, 2016
·
3.899K
· samuelm

PHP 5.3 : Garbage Collector

Since version 5.3 PHP introduced a garbage collector to handle memory leaks issue for big scripts ( a well know feature for C developper )

It's very easy to use and will save a lot of memory for you batch scripts .

Just call

gc_enable();

and you are done .

You can also force collection of any existing garbage cycles by using

gc_collect_cycles();

You read more about the Collecting Cycles here :
http://php.net/manual/en/features.gc.collecting-cycles.php

2 Responses
Add your response

812

Do you have any examples of when one may find a need for this?

over 1 year ago ·
835

I recomand this article about circular references that explain why you need a garbage collector to be enable. http://www.alexatnet.com/articles/optimize-php-memory-usage-eliminate-circular-references

In real life it's needed for background batch operation that could run for hours for example .

over 1 year ago ·