Page 1 of 1

Clearing memory/resources?

Posted: 2007-10-12T07:28:31-07:00
by Jack-S
Hi,
It seems there are three functions related to clearing the memory IMagick uses: removeImage, clear and destroy. Could you explain the difference between these, and which one should I be using when? Also, given that PHP is supposed to clean up any objects that are no longer used, is it actually necessary to destroy/clear the IMagick objects at all?

Thanks,
Jack

Re: Clearing memory/resources?

Posted: 2007-10-15T03:43:08-07:00
by mkoppanen
Jack-S wrote:Hi,
It seems there are three functions related to clearing the memory IMagick uses: removeImage, clear and destroy. Could you explain the difference between these, and which one should I be using when? Also, given that PHP is supposed to clean up any objects that are no longer used, is it actually necessary to destroy/clear the IMagick objects at all?

Thanks,
Jack

removeImage
Removes the current image sequence.

clear
Clears the object to the initial stage (removes all images from the object)

destroy
The object is destroyed, all resources are freed.


Consider the following code:

Code: Select all

$images = array( "img1.png", "img2.png", "img3.png" );

$im = new Imagick();

foreach ( $images as $image )
{
  $im->readImage( $image );
  /* Do something with the image */
  $im->writeImage( $image );
  $im->clear();
}
this code would keep only one image at the time in the active memory. Calling readimage without clear would append the image as a new sequence.

Re: Clearing memory/resources?

Posted: 2007-10-15T03:54:46-07:00
by Jack-S
Ok, cool, thanks.

Re: Clearing memory/resources?

Posted: 2007-10-15T08:08:14-07:00
by ridera
You didn't say for certain; but, I assume when the scrip ends, it clears all the objects from memory

Re: Clearing memory/resources?

Posted: 2007-10-15T08:14:30-07:00
by Jack-S
ridera wrote:You didn't say for certain; but, I assume when the scrip ends, it clears all the objects from memory
Yeah, I was wondering about that as well. I would assume the same, but then, I'd rather not take the risk on a production server. If it didn't, and your dealing with large images it could all go horribly wrong very quickly.

Re: Clearing memory/resources?

Posted: 2007-10-15T23:17:32-07:00
by mkoppanen
ridera wrote:You didn't say for certain; but, I assume when the scrip ends, it clears all the objects from memory

Sorry, forgot to reply to this part. All objects are freed when the script execution ends.