From: ara howard Date: 2008-01-09T13:27:30+09:00 Subject: Re: why does this code leak? On Jan 8, 2008, at 8:53 PM, Michael Bevilacqua-Linn wrote: > Why are you assuming it's leaking without giving the GC a chance to > run? because i'm an idiot and pasted the wrong buffer. here is the code: # # distilled behaviour from dike.rb # class Object Methods = instance_methods.inject(Hash.new){|h, m| h.update m => instance_method(m)} end class Class Methods = instance_methods.inject(Hash.new){|h, m| h.update m => instance_method(m)} def new *a, &b object = Methods["new"].bind(self).call *a, &b ensure ObjectSpace.define_finalizer object, finalizer end def finalizer lambda{} end end # # the above makes this code leaks, but *only* Net::HTTPOK objects # require "net/http" def leak! Net::HTTP.start("localhost") do |http| puts http.get('/').code end end 3.times { puts "---" p ObjectSpace.each_object(Net::HTTPResponse){} leak! GC.start } a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama