From: han.holl@... (Han Holl) Date: 2004-07-07T20:42:38+09:00 Subject: Re: Druby and garbage collection Eric Hodel wrote in message news:<20040707063932.GA5027@segment7.net>... > This is very, very unsafe. Your DatabaseProxy may destroy itself at any > time, since the reference is pulled out of ObjectSpace. You probably > want to use TimerIdConv instead of the default DRbIdConv. > [ cut ] Ah, yes. I see that now. Thanks for pointing that out. I think the solution in this case can be to make the proxy a Singleton, and return DatabaseProxy.instance instead. > > a = Array.new(10000) > > STDERR.puts "Created #{a.object id}"; STDERR.flush > > ObjectSpace::define finalizer(a, proc {|id| > > STDERR.puts "Finalizer #{id}"; STDERR.flush > > }) > > This is the wrong way to define a finalizer. The proc must be created > outside of where self exists, otherwise the block holds onto self, and > self can never be gc'd. (This is a big gotcha! Understanding why this > is wrong took me quite some time to figure out.) Ok, this example works fine now. My original problem was that large returned datasets didn't seem to get garbage collected, and only _after_ that I put the finalizer thing in, and then I simplified the server to the above silly thing. I'll go and recheck the original now, which is too large and too convoluted to post in a message. Thanks a lot for your help, Han Holl (and somehow STDERR.sync doesn't quite work for me).