I have to render something with Imagick on PHP CLI. I have noticed that every 3-5 days the server memory gets full, so i can't even connet via ssh or ftp.

with memory_get_usage() i narrwoed the memory leak down to the imagick part of the script. the script looks something like this:

$sourceImg = 'source.png';
$destImg = 'dest.png';
$background ='#00ff00';

$im = new Imagick();
$im->pingImage($sourceImg);
$im->readImage($sourceImg); 
$draw = new ImagickDraw();

for($i=1;$i<=5;$i++){
    $draw->setFillColor( $background);
    $draw->rectangle( 10*$i+5, 10, 10*$i+10, 20);
} 

$im->drawImage( $draw );
$im->writeImage( $destImg );
$im->destroy();

unset($im,$draw);

I destroy the image reference, and unset the imagick and imagickDraw object, but the script won't release any memory. The setFillColor() method takes the most memory

Can i do something else to free the space used by imageick?

image of the memory consumption

Edit
Report