Topic: Help on Memory Leak

My application (an auction site) runs fine for weeks at a time ...but then mysteriously 'goes down'.  When this occurs, I have to restart Apache - (though it can still serve static pages).

How do I determine if this is a memory leak and if so, what specifically in my code is causing it?

This is the first the Rails app that I've developed and deployed  - so still new to this and to Linux. For example, I know ps and top but I'm not sure how to determine if Passenger is still 'alive'.

Thanks.

Re: Help on Memory Leak

I think you need to monitor the memory usage of your application with 'free -m' and 'top' (sort by memory usage).  Monitor it every day after you start it and see what the memory growth looks like.

For Passenger status/info try the passenger-status and passenger-memory-stats commands.

Last edited by ehud93 (2009-12-04 15:37:57)

Play postseason fantasy sports at Fantasy Postseason - Written in RoR

Re: Help on Memory Leak

ehud - I'll definitely try your suggestions. Thanks!

If I do find a leak, any thoughts as to how to go about pinpointing which code is causing it?

Re: Help on Memory Leak

With respect to pinpointing the cause..

How you pinpoint (and the extent to which you can pinpoint) depends upon whether the leak exists.  It might not be a leak overall.. if you don't have apache configured correctly it could just be a matter of using more virtual memory than you have available -- causing the system to thrash (and struggle).

If you are certain that the leak is specific to the rails processes then you'll need to figure out which action processing is causing it.

There may be some tools out there.. I don't know though.  Start by monitoring system memory levels and then try to see if there's a system memory issue.

Play postseason fantasy sports at Fantasy Postseason - Written in RoR

Re: Help on Memory Leak

I'll start with your suggestion about monitoring system memory and see what I can determine from my observations.

Thanks for your thoughts!

Re: Help on Memory Leak

A common reason is eventhandlers not getting detached. Check that you are not hooking up eventhandlers that stay around, thus keeping the garbage collector from collecting memory.
Btw, calling GC.Collect(); is not sufficient. It should be followed by GC.WaitForPendingFinalizers(); to properly force a collect.
I noticed that the GC in Silverlight is very lazy, it it won't collect until it starts hitting the roof. That means the it will sometimes look like you have a memory leak even though you don't (however adding the above statement after .Collect() will force the collection).

Last edited by arnoldclab (2010-02-04 05:57:21)