Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there garbage collection in PHP?

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

like image 990
Sergey Avatar asked Nov 14 '09 20:11

Sergey


People also ask

Does PHP support garbage collection?

As of PHP 7.3, PHP provides basic garbage collection information in user land PHP, via gc_status. The function returns: The number of garbage collection runs. The number of objects collected.

What languages use garbage collection?

Garbage collection (GC) is a memory recovery feature built into programming languages such as C# and Java.

Does C++ have garbage collection?

A C++ program can contain both manual memory management and garbage collection happening in the same program. According to the need, either the normal pointer or the specific garbage collector pointer can be used. Thus, to sum up, garbage collection is a method opposite to manual memory management.

Does Ruby use garbage collection?

Many modern programming languages manage memory for you, and Ruby is no different. Ruby manages memory usage using a garbage collector (also called gc).


4 Answers

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

like image 150
luvieere Avatar answered Sep 25 '22 08:09

luvieere


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.

like image 37
troelskn Avatar answered Sep 25 '22 08:09

troelskn


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

like image 24
Myles Avatar answered Sep 26 '22 08:09

Myles


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

like image 40
Aris Avatar answered Sep 24 '22 08:09

Aris