Finding memory leaks?

Where are the memory leaks and what is the way to fix them?
I’m working on a game that was fairly stable in terms the memory
consumption
and it was staying at around 200MB. Recently it has gone crazy, and
unless I
restart it, it goes straight up to 350-400+MB after 30 minutes-1hour.
I am using Apache 1.3+fcgi in production mode.
Also the dispatch.fcgi processes take a really high toll (3-5%) on the
CPU.
( 2.4GZ Xeon with 2 procs)
Since it’s hosted (still) on a shared machine I have to constantly keep
an
eye on it.
Any ideas, suggestions?

Thanks,
Bogdan

On 1/8/06, Bogdan I. [email protected] wrote:

Where are the memory leaks and what is the way to fix them?
I’m working on a game that was fairly stable in terms the memory consumption
and it was staying at around 200MB. Recently it has gone crazy, and unless I
restart it, it goes straight up to 350-400+MB after 30 minutes-1hour.
I am using Apache 1.3+fcgi in production mode.
Also the dispatch.fcgi processes take a really high toll (3-5%) on the CPU.
( 2.4GZ Xeon with 2 procs)
Since it’s hosted (still) on a shared machine I have to constantly keep an
eye on it.
Any ideas, suggestions?

It used to be the case that Rails would leak memory when running in
development mode. Not sure if it is anymore.

My application is running in production mode, so it can’t be that

Bogdan I. <bogdan.ionescu@…> writes:

Where are the memory leaks and what is the way to fix them?I’m working on a
game that was fairly stable in terms the memory consumption and it was
staying
at around 200MB. Recently it has gone crazy, and unless I restart it, it
goes
straight up to 350-400+MB after 30 minutes-1hour.
I am using Apache 1.3+fcgi in production mode.Also the dispatch.fcgi processes
take a really high toll (3-5%) on the CPU. ( 2.4GZ Xeon with 2
procs)Since it’s
hosted (still) on a shared machine I have to constantly keep an eye on
it.
Any ideas, suggestions?Thanks,Bogdan

Bogdan,

Two things to look at:

  1. What garbage collection settings do you have in public/dispatch.fcgi?
    If you
    use this syntax:

RailsFCGIHandler.process! nil, 50

Then garbage collection will NOT run until after 50 requests. This one
bit us a
while ago. Use the default instead if your dispatch.fcgis are growing:

RailsFCGIHandler.process!

  1. Here’s a good article on finding leaky objects in Ruby. The tools
    aren’t
    terribly sophisticated but they work just fine if you’re willing to
    spend a
    little bit of time chasing your leak.

http://theexciter.com/articles/finding-leaking-ruby-objects

I got the best results out of using this code to analyze controller
methods
invoked through functional tests. Don’t be afraid to use vendor/plugins
to
override (and inject measurement code) into base Rails classes if the
leak
doesn’t appear to be in your code.

Best of luck,

Tyler

Also, if you are using RMagick, then you will need to perform manual
garbage
collection to get all the used memory back.

I have a method that looks like this that I call after I do a bunch of
operations:

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