From: Lars Christensen Date: 2001-08-12T07:13:40+09:00 Subject: [ruby-talk:19550] Forced garbage collection Hi, I am testing some code that uses ObjectSpace#define_finalizer, but I can not force objects to be garbage collected using GC.start or ObjectSpace.garbace_collect. This code behaves strangely (to me at least) on my box (linux/i386), ruby 1.6.4 debian build, custom build, ruby-1.7.1 checkout today, and rubywin-1.6.4-2 on win98se. ==snip== class Foo attr_reader :val def initialize(val) @val = val end end Foo.new(1) f = Foo.new(2); f = nil (3..5).each{|i| Foo.new(i)} ObjectSpace.garbage_collect ObjectSpace.each_object(Foo) { |f| puts "Foo #{f.val} is here." } ==snip== This code tell me that Foo 1 is still there after the garbage collection has been invoked. If i change the order of the Foo.new calls to: f = Foo.new(2); f = nil Foo.new(1) Then, both Foo 1 and Foo 2 are in memory after garbage collection. I cannot reproduce on Solaris (both intel and sparc). Here, all the object gets deleted. Why this behaviour? A bug? -- Lars Christensen, larsch@cs.auc.dk