Is there garbage collection?

05/20/2020 05:30:02

I know that in PHP you don't have to free memory. Is it reached by garbage collector?

Verified Answer (52 Votes)

11/15/2009 01:31:19

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


Answer #2 (8 Votes)

11/15/2009 03:49:08

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.


Answer #3 (3 Votes)

11/15/2009 01:30:34

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

Hack Hex uses Stack Exchance API by the Stack Exchange Inc. to scrape questions/answers under Creative Commons license.