From: "Sean O'Dell" Date: 2003-09-18T07:51:51+09:00 Subject: Re: Testing for memory leaks Berger, Daniel wrote: > Hi all, > > Being as I write a lot of extensions, I've discovered that it's best to > check for memory leaks. The way I'm doing this now is something like this: > > # pseudo code > while 1 > call some_method > if Linux or BSD > check /proc/Process.pid/fd count > elsif Solaris > check pfiles Process.pid count > elsif Win32 > start Task Manager and watch used file descriptors and memory for > Process.pid > end > sleep 1 > end > > # Ctrl-C to break out of loop only after at least 10 iterations > > Is there a better and/or more streamlined way to do this? Any chance of > adding assert_no_memory_leak to TestUnit, for example? The way I have been handling it is I've been launching an infinite loop that creates instances of my extension and uses it, then calls GC.start every iteration. I launch it as a background process and then run top and watch its memory usage. If it hovers at a certain point and doesn't grow and grow, I assume its safe. To provide a positive, I first deliberately put in code that should prevent the GC from collecting something, then run top. Watch it grow and grow. Put the code back to normal, watch it grow to a certain point and then hover. Sean O'Dell