Understanding memory leaks


#1

Hey list,

My app is leaking; It’s actually more of a gush than just a leak.

I tried using the script from
http://scottstuff.net/blog/articles/2006/08/17/memory-leak-profiling-with-railsbut
to be honest, I couldn’t discern any noticeable pattern from its
output.
From looking at top and clicking various pages on my site, I have a
rough
idea where the leak is coming from, but I think I need some help with
understanding what exactly is capable of causing them.

I have a class with a bunch of class methods and a class variable (I
prefer
this approach over singleton instances). Through the cycle of a single
request, this class stores various objects in a class variable. At the
start of the request, before the class is used, a reset method is
called
to assign nil to the class variable. At the end of the request, the
class is
left as-is, with the class variable still populated with objects. Am I
correct in my assumption that it doesn’t matter if I call the reset
method
at the start or end of the request cycle? In production mode, the state
of
the class should surely be unchanged between requests?

Other than this situation, I fail to see where else in my code a leak
could
occur. if I ever populate arrays in my controllers or models, they all
have
method scope so in theory should be collected by the GC when the method
returns. Controller classes are instantiated on each request in
production
mode, right?

Also, can anyone recommend some tools for detecting leaks other than the
script mentioned above?

Cheers
Ian


#2

On 5/15/07, Ian L. removed_email_address@domain.invalid wrote:

Other than this situation, I fail to see where else in my code a leak could
occur. if I ever populate arrays in my controllers or models, they all have
method scope so in theory should be collected by the GC when the method
returns. Controller classes are instantiated on each request in production
mode, right?

Also, can anyone recommend some tools for detecting leaks other than the
script mentioned above?

Try Bleak House:
http://blog.evanweaver.com/articles/2007/04/28/bleak_house


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com


#3

Some interesting mailing list posts I’ve found interesting while
inspecting my app are

http://tinyurl.com/2qw6l5

http://tinyurl.com/2rdq2m

Bleak house is definitely the tool to use, and is worth just to try to
stress your app and see if the memory usage just keeps to grow or
stops at some point.

Paolo