David Masover
2/11/2009 12:25:00 AM
James Gray wrote:
> * 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
Not sure.
> * Ruby cannot GC a running Thread, even if there are no references to it
Unfortunately, this part is true, as Ruby has not solved the Halting
Problem.
It might be possible to collect a thread if you have very specific
knowledge about when it is no longer needed. The hack I've been playing
with lately is to have all access to the thread be through a specific
object or set of objects, and reap the thread in the finalizer(s) of
those object(s).
The part I haven't solved is circular references -- anything one thread
has a reference to can't be collected as long as that thread is running,
so if thread A knows about thread B, which also knows about thread A,
they will have to be manually cleaned, even if that knowledge is purely
through such proxy objects.
Oh -- the above rambling might make sense in context. I'm writing an
actor library. I can picture a state where a collection of actors should
be collected, as they're all out of messages and only referred to by
each other -- but while I theoretically should be able to write a
garbage collector for that, I can't figure out how to do it in Ruby
without at least writing a C extension.