4 ms·
There is a garbage collection: https://www.php.net/manual/en/features.gc.php https://www.php.net/manual/en/features.gc.php > This section explains the merits
by Isinlor 5y ago
There is a garbage collection:
https://www.php.net/manual/en/features.gc.php https://www.php.net/manual/en/features.gc.php
> This section explains the merits of the new Garbage Collection (also known as GC) mechanism that is part of PHP 5.3.
> First of all, the whole reason for implementing the garbage collection mechanism is to reduce memory usage by cleaning up circular-referenced variables as soon as the prerequisites are fulfilled. In PHP's implementation, this happens as soon as the root-buffer is full, or when the function gc_collect_cycles() is called. In the graph below, we display the memory usage of the script below, in both PHP 5.2 and PHP 5.3, excluding the base memory that PHP itself uses when starting up.
- mojuba 5y agoPHP's garbage collector is ARC, unlike any other dynamic language that I know of. ARC is more performant but can introduce memory leaks via circular references, which is probably not a big problem for short-lived scripts anyway.
- nicoburns 5y agoSounds optimal for PHP where 99% of scripts are short lived.
- JiNCMG 5y agoWhich is perfect for a HTTP request.
- Isinlor 5y agoI'm not sure if you did not read what I quoted, or I misunderstand something. Yes, PHP has reference counting, but it also has specific process that kicks in to clean up circular references.
- kaba0 5y agoHow is it more performant? If you have multiple threads than you will get serious atomic operation or other synchronization overhead.
- Isinlor 5y agoPHP is share-nothing architecture. Nobody really uses threads in mainline PHP. Whole class of problems around multi-threading, mutexes, dead locks etc. are really foreign to PHP developers.
- kaba0 5y agoYeah, I should have mentioned that in the general case RC is not more performant (otherwise threaded managed languages would use it).
- housecarpenter 5y agoPython uses ARC plus a tracing GC for dealing with cycles, same as PHP: https://devguide.python.org/garbage_collector/ https://devguide.python.org/garbage_collector/ Perl uses ARC with no tracing GC, so you have to handle cycles yourself: https://www.perlmonks.org/?node_id=1173079 https://www.perlmonks.org/?node_id=1173079 TCL uses ARC, and apparently doesn't need a tracing GC because it is impossible to create cycles in it: https://wiki.tcl-lang.org/page/Garbage+collection https://wiki.tcl-lang.org/page/Garbage+collection
- Zababa 5y agoARC is not more performant, it's more deterministic. "regular" GCs have better throughput. RC in general also handles other resources (like files) a bit better than GC.
- fooyc 5y agoPHP has a GC since 2009 (version 5.3). Its goal is precisely to collect reference cycles.