Memory leaks when using insert function, even with destroy.
Author: zsimpleCreated Aug 2, 2017Updated May 27, 2025
Labelsinvestigation-needed
I wrote a laravel command to operate many images, something like that:
while (true) { // use while-true to simulate lots of images
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')); // without this save, grows much slower. It is another encode leaks issue I think.
$img->destroy(); // without these two destroy, script booms very quickly.
$image->destroy();
usleep(25);
}
}The memory usage grows about 1M per second on my PC.
By the way, I am using GD2 driver on Windows. Maybe it's an issue of GD? I will try it on Linux later.
Anyidea?
Source: Intervention/image