Steffen Hi, the name's Steffen and I'm writing about the Web, programming and all those things coming to my mind. Enjoy your stay.

I'm currently working on fabidoo.com - 3D Printing for everyone!

Memory Leaks in GetText for Ruby on Rails

Version 1.90.0 of GetText for Ruby has quite some memory leaks in its Rails support files. In my case, the memory Mongrel used increased by 1 MB with each request it served… Quite amazing that you don’t really find someone else having the problem… Well there’s at least a bug report on rubyforge…

Monkey-patching gettext.rb with the following code made things quite more relaxed:

  def bound_target(klass = self) # :nodoc:
    ret = nil
    if klass.kind_of? Class or klass.kind_of? Module
      ret = klass
    else
      ret = klass.class
    end
    ret = GetText if ret.name =~ /^\#<|^$/
    ret
  end

The memory usage grows extremly slow now and is acceptable for our current web site traffic.

Plus: It helps to “every now and then” call GetText.clear_cache - which I don’t like because you have to do it “manually”. It would be much better if GetText did its own garbage collection …

Tags: , , ,

2 Responses to “Memory Leaks in GetText for Ruby on Rails”

  • 1
    Michael Says:

    You’re not alone!
    My site http://dailyfratze.de is run on rails with rgettext and i do have the exact same problem. I’ll try your patch… In any case, thanks for sharing!!

  • 2
    Mike C Says:

    This patch was a lifesaver. Without it, gettext leaks every string in every class it touches.

  • Leave a Reply

18552