From: Wilson Bilkovich Date: 2007-01-04T00:45:13+09:00 Subject: Re: Memory Leak Madness On 1/3/07, Brandon Casci wrote: > I'm having one hell of a time trying to find and stop a memory leak in a > ruby daemon. It starts off using a tiny 14 MB of RAM, and 150+MB after a > day. I've read through many forum and blog posts, and tried several > profilers. I don't see anything unusual. > > I even tried this guy > http://scottstuff.net/blog/articles/2006/08/17/memory-leak-profiling-with-rails > > That showed my overall object count going up and down as normal, but > memory was not being released as objects came and went. > > I've gone through my code made sure I'm squashing any unused objects. > Well...I set them to nil, I just guessed that would help. I'm also > calling .clear on any arrays and hashes. I noticed this helps with > garbage collection. I also added a thread that runs does nothing but > sleep and run garbage collection every 5 minutes, although I'm pretty > sure this isn't helping much. > > All I've managed to greatly slow the memory leak. Before the daemon > would consume 100+ MB in a few hours. > > There are two things my daemon makes heavy use of that is out of > control, hpricot and dbi (talking to ms sql server). I suspect one or > both of these guys may be my problem. I'll write into both projects for > advice, but is there anything else I can do so ruby will let go of > unused objects? Try loading this library when you daemon starts up: http://moonbase.rydia.net/mental/blog/programming/fastthread-0-6-1.html DBI almost certainly makes use of locking, and fastthread cleans that up significantly. Just a thought.