From: Eric Mahurin Date: 2005-06-21T04:11:32+09:00 Subject: Re: GC.disable not working? --- Robert Klemme wrote: > > I have tried Thread.critical= which is what Mutex and > probably > > other mutual exclusivity stuff are based on. The problem > is > > that GC/finalizers is not considered to be in separate > threads. > > But in that case one of the two might help - the one that > isn't reentrant, > would it? I'll go look at this again. I all of this had to do with exclusivity between threads. If I can do it within one thread, that may work. > def testit > obj = Object.new > ObjectSpace.define_finalizer(obj) {|oid| puts "cleanup > #{oid}" } > obj = nil > end > > > 10.times do > 1000.times { testit } > GC.start > sleep 1 > end > > puts "end" ... > Also, the oids seem not reused (see the sort output). I find them reused. I modified your code a little to track what's been used: @used = {} def testit obj = Object.new id = obj.object_id @used[id]==false and puts("reused #{id} after finalizing") @used[id] = true ObjectSpace.define_finalizer(obj) {|oid| #puts "cleanup #{oid}" begin ObectSpace._id2ref(oid) puts("reused #{id} before finalizing!!!!!!!!!!") rescue RangeError end @used[oid] = false } obj = nil end 10.times do 1000.times { testit } GC.start sleep 1 end Fortunately, I never see it reuse id's before the object for that id is finalized. > A solution to tackle the oid reuse issue (if it's an issue) > would be to > store something that can verify that the oid belongs to the > data stored for > that oid. Unfortunately I can't think of a way ATM... That's kind of what WeakRef does. Unfortunately it is about 20X slower than using simple object ids. Using GC.start with object ids is much faster. ____________________________________________________ Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com