From: James Gray Date: 2009-02-11T07:58:30+09:00 Subject: Re: GC and Threads On Feb 10, 2009, at 4:51 PM, James Gray wrote: > I'm trying to prove two simple facts about how Ruby works: > > * Ruby can GC a Thread that has run to completion if you no longer > have any references to it, even if the value() have never been > collected > * Ruby cannot GC a running Thread, even if there are no references > to it > Simple scripts I've written seems to indicate they are accurate… Actually, this is difficult to judge. For example, this script has odd results on my machine. The Thread count does drop, but not all the way: #!/usr/bin/env ruby -wKU def show_thread_count count = 0 ObjectSpace.each_object(Thread) { |obj| count += 1 } p count end show_thread_count 5.times do Thread.new do date = `sleep 1 && date` end end 20.times do sleep 0.2 3.times { GC.start } show_thread_count end __END__ Here's a pretty typical output, though it varies a little: $ ruby testing_thread_gc.rb 1 6 6 6 6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Thoughts? James Edward Gray II