#29558 [Opn->Fbk]: Memory leak when calling imageCreateFromJPEG and imagecreatetruecolor in loop
| From: | pajoye@php.net | Date: | Fri, 19 Nov 2004 12:47:48 +0000 |
| Subject: | #29558 [Opn->Fbk]: Memory leak when calling imageCreateFromJPEG and imagecreatetruecolor in loop | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-69261@lists.php.net to get a copy of this message | ||
ID: 29558
Updated by: pajoye@php.net
Reported By: zsheran at yahoo dot com
-Status: Open
+Status: Feedback
Bug Type: GD related
Operating System: Redhat 9
PHP Version: 4.3.7
Previous Comments:
------------------------------------------------------------------------
[2004-11-19 13:46:48] pajoye@php.net
Are you talking about real memory leaks (memory not freed at the end of
the process) or about the memory used by php?
--Pierre
------------------------------------------------------------------------
[2004-08-10 10:09:46] klaus at deam dot org
maybe this is related to bug #29460?
------------------------------------------------------------------------
[2004-08-08 05:34:47] zsheran at yahoo dot com
Thanks smacvicar.
I made the following change at the bottom of the function:
replaced
unset($source_picture);
unset($target_picture);
with
imagedestroy($source_picture);
imagedestroy($target_picture);
The problem persists. It still leaks memory the same way it did before.
I didn't know imagedestroy() had to be used instead of unset(); my
fault. But now it looks even more like a bug to me...
------------------------------------------------------------------------
[2004-08-07 04:43:35] smacvicar at gmail dot com
http://uk.php.net/manual/en/function.imagedestroy.php
------------------------------------------------------------------------
[2004-08-07 00:14:14] zsheran at yahoo dot com
Description:
------------
I call the function below from a loop about 17,000 times to resize JPGs
which are about 20k each. Note that $source_file is a URL. I run the
script from CLI. By the time the script finishes after ~270 minutes,
the PHP process uses 340MB of RAM; it grows slowly and steadily to that
size. I unset the variables at the end of the function but it makes no
difference. Now 340MB is about the size of those 17,000 pics. For some
reason, the fetched images are not freed from memory, probaly only upon
finishing the script. But since it runs in a loop, it adds up at becomes
eventually a problem. It works but it would be great if the memory leak
could be fixed; I expect the number of images to grow to six digit
numbers in the future.
Thanks for your time.
Reproduce code:
---------------
function resize_picture ($source_file, $target_file) {
$source_picture = imageCreateFromJPEG($source_file);
if ($source_picture) {
$picsize = @getimagesize($source_file); // get source image
size
$source_x = $picsize[0]; // source image width
$source_y = $picsize[1]; // source image height
#create image $target_picture
$target_picture = imagecreatetruecolor(320, 240);
#Resize $source_picture and copy it into $target_picture.
imagecopyresampled($target_picture,$source_picture,0,0,0,0,320,240,$source_x,$source_y);
#Create jpeg from $target_picture. Save as $target_file
imagejpeg ($target_picture,"/path/$target_file",80);
unset($source_picture);
unset($target_picture);
}
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29558&edit=1