From: Eric Mahurin Date: 2005-06-19T06:32:44+09:00 Subject: GC.disable not working? From what I can tell, GC.disable doesn't work. I'm wanting to use GC.disable/GC.enable around code using objects that I get from ObjectSpace._id2ref to make sure that the id doesn't become invalid because of GC. Here is a piece of code that demonstrates the problem: #!/bin/env ruby def finalizer(id) print("<") GC.enable and printf("GC disabled while finalizing %x!!!",id) @ids.delete(id) print(">") end $stdout.sync=true @ids = {} 1000.times { |i| print("[") obj = "X"*i id = obj.object_id @ids[id] = true ObjectSpace.define_finalizer(obj,method(:finalizer)) GC.disable print("{") @ids.each_key { |id| # go make sure all objects seem valid (test size) ObjectSpace._id2ref(id).size } print("}") GC.enable print("]") } I tried this on 1.8.2 and a 1.9 CVS version. In both it calls the finalizer when GC is disabled (GC.enable==true). I thought this would be impossible. I also get a recycled object error. In the 1.9 version I'm using, it hangs while trying to finalize one of the objects (@ids.delete(id) is where it hangs). Any clues to what is going on with this GC stuff. If I can't get this to work, I don't see how anybody reliably use ObjectSpace._id2ref. BTW, I found this problem in my code after running tens of thousands of random tests. If you don't do enough testing, you may not find problems related to garbage collection. __________________________________ Yahoo! Mail Mobile Take Yahoo! Mail with you! Check email on your mobile phone. http://mobile.yahoo.com/learn/mail