Sergey
Sergey

Reputation: 49728

Is there garbage collection in PHP?

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

Upvotes: 64

Views: 55527

Answers (5)

luvieere
luvieere

Reputation: 37494

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

Upvotes: 59

Aris
Aris

Reputation: 5057

since 5.3.0 there is garbage collection support. please check this very informative article from php.net http://php.net/manual/en/features.gc.php

Upvotes: 3

W.Ed.
W.Ed.

Reputation: 11

Since 5.3.0 you can force garbage collection by using gc_collect_cycles function.

Upvotes: 1

troelskn
troelskn

Reputation: 117487

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.

Upvotes: 11

Myles
Myles

Reputation: 21510

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

Upvotes: 3

Related Questions