Alex Rivera | Logout

How to deal with memory leaks in RMagick in Ruby?

Asked 2009-06-06T00:45:17.090
16

Im developing web-application with Merb and im looking for some safe and stable image processing library. I used to work with Imagick in php, then moved to ruby and start using RMagick. But there is a problem. Long running scripts causing memory leaks. There are couple solution exists, but I don't know which one is the most stable. So, what do you think?

Right now, my app uses internal API that i wrote to process images, in PHP. Its running on separate server along with other applications, so its not a big problem. But i think its not a good architecture.

Anyway, i`ll consider any practical tips.

Edit
Report

1 Answer

11

I too have encountered this issue - the solution is to force garbage collection.

When you have reassigned the image variable to a new image simply use GC.start to ensure the old reference is released from memory.

On later versions of RMagick, I also believe you can also call destroy! on the image when you have finished processing it.

A combination of the two would probably ensure you are covered, but im not sure of the real life impact on performance (I would assume it is negligible i most cases).

Alternatively, you could use mini-magick which is a wrapper for the ImageMagick commandline client.

answered 2009-06-06T01:07:03.817

Your Answer