-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image::encode() leaks memory #426
Comments
I would use destroy() to free memory in each iteration. Unsetting the image after encoding, might not be always wanted. |
That doesn't fix the problem, it still leaks, just a lot less. Better workaround is to call |
So this seems to be a problem of the GD function. Or is it the code from Intervention Image leaking memory? |
This is an issue with Intervention Image itself (it can be reproduced with both gd and imagick), I believe what is happening is:
That's why unsetting the I hope that makes at least some sense, I'm pretty awful at explaining stuff. :) |
+1 |
I can confirm that Test case using this picture (on the filesystem): require 'vendor/autoload.php';
use Intervention\Image\ImageManager;
$manager = new ImageManager(array('driver' => 'imagick'));
for ($i = 0; $i < 10; $i++) {
$image = $manager->make(__DIR__ . '/lichtenstein.jpg');
$image->encode('png');
$image->destroy();
echo "$i. " . memory_get_peak_usage(true) . "\n";
} Output without
Output with
But it still takes 20.45 seconds to process the whole script using the Imagick driver and 16.75 seconds using the GD driver. Server details: |
- Memory leak is fixed in vendor, see: Intervention/image#426 - Loading time is still very long (previous commit did not fix it)
Can this also be fixed on 2.2.2? It's the latest version for PHP 5.3, which we use. |
Ran into this when trying to batch optimize a bunch of jpegs today... |
I am not entirely sure if this is what I ran into yesterday, but we had a script processing images and it caused system OOM after processing a few hundred images. We are using ImageMagick. |
Hey, I'm working on a batch script that processes lots of images in a loop, always crashing due to memory exhaustion caused by intervention/image. Here is a very simplified script that reproduces this problem:
I've traced this problem to this assignment https://github.com/Intervention/image/blob/master/src/Intervention/Image/AbstractEncoder.php#L87, which I believe creates a circular reference between the Image and Encoder instances, causing the memory to never be freed.
Simply unsetting the
$this->image
reference after the image is encoded fixes this problem.The text was updated successfully, but these errors were encountered: