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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:39:53  来源:igfitidea点击:

Is there garbage collection in PHP?

phpmemory-managementgarbage-collection

提问by Sergey

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

我知道在 PHP 中你不必释放内存。它是由垃圾收集器到达的吗?

采纳答案by luvieere

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

是的,[这里] 是一篇很好的文章,描述了它的陷阱。在 PHP > 5.3.0 中,还有gc_enable函数。

回答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.