PHP 中有垃圾收集吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1735492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there garbage collection in PHP?
提问by Sergey
I know that in PHP you don't have to free memory. Is it reached by garbage collector?
我知道在 PHP 中你不必释放内存。它是由垃圾收集器到达的吗?
采纳答案by luvieere
回答by troelskn
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.
PHP 结合了垃圾收集和引用计数。后者是管理内存的主要模式,垃圾收集器收集引用计数器未命中的部分(循环引用)。在 5.3 之前,php 只有 ref-counting,即使在 5.3 中,它仍然是通常会释放内存的方式。
回答by Myles
Yes. There is also session cleanup done by the garbage collector.
是的。垃圾收集器还会进行会话清理。
回答by Aris
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
从 5.3.0 开始有垃圾收集支持。请从 php.net http://php.net/manual/en/features.gc.php查看这篇内容丰富的文章
回答by W.Ed.
Since 5.3.0 you can force garbage collection by using gc_collect_cycles function.
从 5.3.0 开始,您可以使用gc_collect_cycles function.

