2
我運行一個循環,其中包含一個腳本,用於識別圖像中的白色背景,然後複製沒有白色背景的圖像的裁剪版本。在循環結束時,我使用imagedestroy釋放內存,但腳本仍然超過內存限制(> 256mb)。 這怎麼可能?Imagedestroy不能釋放內存
代碼內環:
$img = imagecreatefromjpeg($imgSrc);
/* Script for identifying whitespace */
//create new image
$newimg = imagecreatetruecolor(
imagesx($img)-($wsLeft+$wsRight), imagesy($img)-($wsTop+$wsBottom));
//get new width and height
$width = imagesx($newimg);
$height = imagesy($newimg);
//free memory
imagedestroy($newimg);
imagedestroy($img);
PHP是垃圾回收 - 只是因爲你在你的代碼中銷燬一個變量並不意味着內存被立即釋放。 [閱讀此](http://php.net/manual/en/features.gc.php)瞭解更多信息。做`$ img = $ newimg = NULL;`可能會有所幫助。 – DaveRandom 2011-12-15 13:36:46