Nathaniel Talbott wrote:
> james_b [mailto:james_b / neurogami.com] wrote:
>>Is this a quirk of Test::Unit?  Or of ObjectSpace?
> 
> 
> I don't think Test::Unit is doing anything funky; my guess is that it's just
> a quirk of Ruby's garbage collector. I don't know exactly how the GC
> interacts with ObjectSpace, but my guess is that one can think of the
> ObjectSpace as having weak references to all the objects created, so it
> doesn't prevent GC of those objects. However, GC timing in Ruby is not
> guaranteed, and thus it wouldn't surprise me if there are cases when objects
> with no remaining references are still found by an ObjectSpace walk. Why it
> only shows up when testing, I have no earthly idea. Have you tried
> sacrificing a chicken to the GC before every test run? 

Hm.  That'a an idea ...

 > If that's a bit too
> messy, your solution of calling ObjectSpace#garbage_collect in teardown is
> probably the next best thing. Another solution would be to pass the
> ObjectSpace in to the code that uses it - that way you can use a mock when
> testing that code and not be dependent on the GC at all.

The code being tested loops over ObjectSapce.  Oddly, calling 
ObjectSpace#garbage_collect in that code right before iterating didn't 
help.

Is there a way to ask an object if nothing refers to it?

> 
> HTH,

Thanks,

James

> 
> 
> Nathaniel
> 
> <:((><
> 
> 
>