Ruby on Rails
How to debug memory consumption problems or memory leaks

1. First, check your code to see if what you’re dealing with is in fact a leak; in Rails, leaks generally happen if you keep around a stale global reference. Make sure you’re not doing this and that you know and understand Ruby’s variable naming conventions;

2. Try not to trash memory (this means try not to use/allocate useless objects, particularly not in a tight and big loop, for example)—read this: http://whytheluckystiff.net/articles/theFullyUpturnedBin.html for useful information as far as typical trashing scenarios are concerned;

3. Read this: click here—it explains how sometimes you may think you have a leak but in fact you do not.

4. If you are using RMagick, check out this information about memory usage: http://rubyforge.org/forum/forum.php?thread_id=1374&forum_id=1618

That page indicates to perform a GC.start, but that call doesn’t work if garbage collection is disabled. I use this code:

  def run_gc
    fDisabled = GC.enable
    GC.start
    GC.disable if fDisabled
  end