From: zsheran at yahoo dot com Operating system: Redhat 9 PHP version: 4.3.7 PHP Bug Type: GD related Bug description: Memory leak when calling imageCreateFromJPEG and imagecreatetruecolor in loop
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 bug report at http://bugs.php.net/?id=29558&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29558&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29558&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=29558&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=29558&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=29558&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=29558&r=needscript Try newer version: http://bugs.php.net/fix.php?id=29558&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=29558&r=support Expected behavior: http://bugs.php.net/fix.php?id=29558&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=29558&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=29558&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=29558&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29558&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=29558&r=dst IIS Stability: http://bugs.php.net/fix.php?id=29558&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=29558&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=29558&r=float