加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

资源上的PHP垃圾收集器?

发布时间:2020-12-13 17:37:23 所属栏目:PHP教程 来源:网络整理
导读:采取这个简单的循环 while(1) { $data = file_get_contents('randomfiles.img'); $resource = imagecreatefromstring($data); // do some image operation and other stuff // continue // not calling imagedestroy($resource);} 正如你所看到我没有调用ima
采取这个简单的循环

while(1) {
    $data = file_get_contents('randomfiles.img');
    $resource = imagecreatefromstring($data);

    //> do some image operation and other stuff
    //> continue

    //> not calling imagedestroy($resource);

}

正如你所看到我没有调用imagedestroy,但我使用相同的变量($resource)来存储imagecreatefromstring()的输入; (类型资源)

当一个新循环启动时,php GC自动释放以前的$资源?

我们只考虑PHP 5.3

谢谢

解决方法

从 http://de2.php.net/manual/en/language.types.resource.php起

Freeing resources

Thanks to the reference-counting system introduced with PHP 4’s Zend Engine,a resource with no more references to it is detected automatically,and it is freed by the garbage collector. For this reason,it is rarely necessary to free the memory manually.

Note: Persistent database links are an exception to this rule. They are not destroyed by the garbage collector. See the persistent connections section for more information.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读