From: Eric Mahurin Date: 2005-10-16T13:21:19+09:00 Subject: Re: Help! define_method leaking procs... --- Yohanes Santoso wrote: > Eric Mahurin writes: > > > n=2**13;(1..n).each{|i| > > > a=(1..i).to_a;self.class.send(:define_method,:"f#{i}"){i*i}};GC.start; > > > IO.readlines("/proc/#{Process.pid}/status").grep(/VmSize/).display' > > VmSize: 172028 kB > > > ruby -e ' > > n=2**13;(1..n).each{|i| > > > a=(1..i).to_a;self.class.send(:define_method,:"f#{i}"){i*i};a=nil};GC.start; > > > IO.readlines("/proc/#{Process.pid}/status").grep(/VmSize/).display' > > VmSize: 11504 kB > > Stop right there. I want to remind people that you can't use > VmSize as > a leak indicator. In some OS, VmSize is an always increasing > number. Memory allocated in a process is not returned to the > OS until > the process dies. OK. Pick another way to measure memory. top shows the same memory as above for me. Or make n=2**15. This brings my machine (768MB) to its knees: ruby -e 'n=2**15;(1..n).each{|i| a=(1..i).to_a;self.class.send(:define_method,:"f#{i}"){i*i}};GC.start; IO.readlines("/proc/#{Process.pid}/status").grep(/VmSize/).display' I'd estimate it would use about 3GB. And if you put an a=nil after the define_method, you get this: ruby -e 'n=2**15;(1..n).each{|i| a=(1..i).to_a;self.class.send(:define_method,:"f#{i}"){i*i};a=nil};GC.start; IO.readlines("/proc/#{Process.pid}/status").grep(/VmSize/).display' VmSize: 31032 kB __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com