ID:               29558
 Comment by:       smacvicar at gmail dot com
 Reported By:      zsheran at yahoo dot com
 Status:           Open
 Bug Type:         GD related
 Operating System: Redhat 9
 PHP Version:      4.3.7
 New Comment:

http://uk.php.net/manual/en/function.imagedestroy.php


Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to