标签:php resources garbage-collection
采取这个简单的循环
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.
标签:php,resources,garbage-collection 来源: https://codeday.me/bug/20190614/1237776.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。