[Backgroundrb-devel] Memory leak?

Joel Hayhurst joel at luckyoliver.com
Mon Aug 7 18:51:28 EDT 2006

I am using BackgrounDRb to resize images after they are accepted into  
our system.  However, it has become clear that this creates a memory  
leak.  I'm not sure exactly where the leak exists, but I don't think  
it's in my own code as it is presently being used in production and  
has resized thousands of images without a leak occurring, thanks to  
calling GC.start after every RMagick image read.

I have it working like this.  First of all, I changed the start  
script to include environment.rb and therefore the ENTIRE Rails  
environment, because my Image model is an engine plugin.  Then, I  
have it perform this upon acceptance:

         MiddleMan.new_worker :class => :resize_worker, :args => self.id

And here are the contents of ResizeWorker:

class ResizeWorker < BackgrounDRb::Rails
   def do_work(args)
     image = Image.find(args)

If I run this on a few dozen images simultaneously I watch as top  
starts slowly requiring more memory for backgroundrb.  Dropping into  
script/console tells me two things.

For one, MiddleMan.jobs still has every job, despite my terminate()  
call.  Second, calling destroy_worker on any of these calls, or gc! 
(Time.now), does not free up any of the memory, even though the jobs  
disappear.  GC.start also does not free up any memory.

If you have any advice on this, that would be great.


More information about the Backgroundrb-devel mailing list