我需要在这个循环中使用 imagedestroy() 吗?

发布于 2024-12-01 03:31:02 字数 327 浏览 4 评论 0原文

我使用相同的变量创建大量图像,因此每个图像都会覆盖前一个图像。我需要使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天涯离梦残月幽梦 2024-12-08 03:31:02

根据您正在执行的操作,您应该将 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文