Forum: Ruby on Rails Image format gotcha

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
807e34b31d5463a9ac05d41458a9e537?d=identicon&s=25 Al Evans (al-evans)
on 2006-05-16 14:10
I've been doing a lot of testing witn RMagick lately, in view of reports
that it leaks memory. I'm happy to report that RMagick doesn't seem to
leak at all, when used as directed -- that is, when you remember to set
the image variable to nil and call GC.start manually after you're done
with an image.

BUT -- one ImageMagick format seems to be leaky! I was using the native
"MPC" format to store an intermediate image for processing, since
(according to the ImageMagick docs) it maps directly into memory and
should be very quick-loading. I kept seeing big increases in
virtual-memory allocation every time I used that image. The problem went
away when I changed the format of the intermediate file to anything else

Here's the quickie script I sent to Timothy Hunter demonstrating the
problem. I've only tested it on a Mac (OS 10.4.6), so it might be
OS-specific. You might have to change the ps command -- what you're
interested in is virtual memory allocation.

--Al Evans


#!/usr/bin/env ruby

require 'RMagick'
include Magick

# name of original photo without extension
def photo_basename(name)
  name.gsub(/\.\w+$/i, '')

def make_image_cache(pic_file_name)
  img =
  img.strip!.change_geometry("1024x1024") { |cols, rows, img|
    img.resize!(cols, rows)
  img = nil

def make_image_workfile(pic_file_name)
  img ="#{photo_basename(pic_file_name)}.MPC").first
  img.strip!.change_geometry("640x512") { |cols, rows, img|
    img.resize!(cols, rows)
  img.write("#{photo_basename(pic_file_name)}_work.JPG") { self.quality
= 50 }
  img = nil

while true
  puts `ps -l | grep ruby`
This topic is locked and can not be replied to.