我需要在php中释放该对象吗?
之前我在 iPhone 开发中使用过 Objective-C。看来我需要在后端站点做一些工作,我为此选择了 PHP。在 Objective-C 中,我需要在使用对象后释放它们。我也需要在 PHP 中执行此操作吗?谢谢。
Previously I've used Objective-C in iPhone Development. It seems I need to do some work in the back-end site, I chose PHP for this. In Objective-C, I need to release objects after I use them. Do I need to do this in PHP also? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
99.9% 的情况下,您不需要删除该对象。 PHP 有一个垃圾收集器可以为您处理这个问题。一旦代码中不再需要给定的内存实例,垃圾收集器将释放它。
要了解更多信息:
http://php.net/manual/en/features.gc.php
99.9% of the time, no you do not need to delete the object. PHP has a garbage collector that will handle that for you. The garbage collector will free a given instance of memory once it is no longer needed in your code.
To read more:
http://php.net/manual/en/features.gc.php
您不需要排除持久数据库连接。
http://php.net/manual/en/language.types.resource.php
You don't except for persistent database connections.
http://php.net/manual/en/language.types.resource.php
不是为了内存,PHP 使用垃圾收集。对象在代码无法访问后的某个时刻被释放(不是,正如一些简化的介绍所声称的那样)。这包括自几个版本以来的引用循环(a 引用 b,b 引用 a) - 以前,它仅使用引用计数,因此在面对此类循环时失败。
资源(文件、数据库连接等)在收集时可能会被关闭,但由于收集时间是不确定的,并且是否关闭它们取决于相关资源,因此仅仅关闭它们可能是一个非常糟糕的主意当你处理完它们后就离开它们。
Not for memory, PHP uses garbage collection. Objects are released at some point after they become unreachable (not instantly as some simplified introductions claim) to your code. This includes reference cycles since a few versions (a references b, b references a) - previously, it used reference counting only and thus failed in the face of such cycles.
Resources (files, database connections, etc.) might happen to be closed when they are collected, but since the time of collection is non-deterministic and whether that closes them depends on the resource in question, it's propably a very bad idea to just leave them when you're done with them.
不,你不! Php 有一个垃圾收集器,负责为您处理内存。
No. You don't! Php has a garbage collector that take care of memory handling for you.