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
Written by Samuel Merlet
Related protips
2 Responses
Do you have any examples of when one may find a need for this?
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 .