Possible Duplicate:
Is there garbage collection in PHP?
In java there is a concept called Garbage Collector. In java an Object becomes Eligible for Garbage Collection when it’s not reachable from any live threads or any static refrences in other words you can say that an object becomes eligible for garbage collection if its all references are null.
What will happen in PHP? Will it lead to a memory overflow. Is this a disadvantage in PHP or is there ways to handle and what are the ways and techniques PHP provides to handle memory efficiently?
PHP does have a garbage collector, but previous to PHP 5.3 (5.2?) it could not handle circular references and would be unable to GC certain constructs,. e.g.
$a = &$a;
would cause a memory leak. PHP will not run the GC unless it has to, as a GC run is expensive, and usually not needed as most PHP scripts are short-lived. The GC will kick in only when memory pressure is present, and you’ll get an OOM error only if enough memory can’t be freed at all.