#762·image

使用 insert 函数时出现内存泄漏,即使使用 destroy 也一样。

作者: zsimple创建于 2017年8月2日更新于 2025年5月27日
标签investigation-needed

我写了一个 Laravel 命令来操作许多图像,大概是这样的: while (true) { // 使用 while-true 来模拟大量图像 foreach (Storage::files('tmp') as $file) { echo $file, "\n"; $image = Image::make(storage_path('app/' . $file)); // $img = Image::make(storage_path('app/' . $file)); $img = clone($image); $img->crop(200, 100); // $this->some($img); $image->insert($img); $image->save(storage_path('tmp.png')); // 如果不使用此 save,则增长速度会更慢。我认为这是另一个编码泄漏问题。 $img->destroy(); // 如果不使用这两个 destroy,脚本会很快崩溃。 $image->destroy(); usleep(25); } 在我的 PC 上,内存使用量每秒大约增加 1M。顺便说一句,我在 Windows 上使用 GD2 驱动程序。也许这是 GD 的问题。稍后我会在 Linux 上尝试一下。有什么想法吗?

内容来源: Intervention/image