The following message is a courtesy copy of an article that has been posted to comp.lang.misc as well. Hi, Dave Thomas <Dave / Thomases.com> writes: |I was playing with weak references, and came up with a problem with |garbage collection control. It goes something like this: | |There are two ways to check for the validity of a weak reference. | |1. Use it, and rescue a WeakRef::RefError exception | |2. Check that it is valid using weakref_valid? | |If I wanted to use weakref_valid?, and not exceptions, it seems to me |I'd have to disable GC around the use. In a single threaded program, I |could use something like: weakref_valid? cannot assure more than validness at the specific moment. In such racy condition, I think you have to rely on exceptions. |So... Am I making this too complicated? Is there an easier/better way |to control GC in a multi-threaded application? Or, alternatively, |should the nesting count be added to the existing GC module? I don't want to be under such circumstance where several threads need to disable GC, which I think should be avoided. Let's discuss about it. If it is needed, adding nesting count to GC.{enable,disable} is pretty easy. matz.