Is there garbage collection in PHP? Is there garbage collection in PHP? php php

Is there garbage collection in PHP?


Yes there is, here's a nice article describing its pitfalls. In PHP > 5.3.0, there is also the gc_enable function.


PHP has a combination of garbage collection and reference counting. The latter is the main mode of managing memory, with the garbage collector picking up the pieces that the ref counter misses (circular references). Before 5.3, php only had ref-counting, and even in 5.3 it's the still how memory will usually be freed.


Yes. There is also session cleanup done by the garbage collector.