我需要在这个循环中使用 imagedestroy() 吗?
我使用相同的变量创建大量图像,因此每个图像都会覆盖前一个图像。我需要使用imagedestroy()
吗?
前任:
<?php
foreach($paths as $path) {
$image = imagecreatefrompng($path);
//more code...
imagedestroy($image); //--------> should i do this?
}
imagedestroy($image); //---------> or should i do this?
I'm using the same variable to create a lot of images, so each one overrides the previous one. Do I need to use imagedestroy()
?
ex:
<?php
foreach($paths as $path) {
$image = imagecreatefrompng($path);
//more code...
imagedestroy($image); //--------> should i do this?
}
imagedestroy($image); //---------> or should i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您正在执行的操作,您应该将
imagedestroy()
放入循环中,以释放内存并为下一个图像腾出空间。另一方面它并没有什么伤害Depending on what you are doing exactly you should put
imagedestroy()
within the loop to free the memory and make space for the next images. On the other hand it just doesn't hurt