From: james_b Date: 2003-08-01T10:28:36+09:00 Subject: Test::Unit leaving phanthom objects in ObjectSpace? I have some code that examines the objects in ObjectSpace and returns a set with all those that meet some criteria. I found during unit testing that, although I have just one (global) varible refering to an object of a particular type, iterating over ObjectSpace.each_object returns numerous objects of this class after some test methods have been called. My unit test code has this: def setup $foo = Foo.new( "Test!" ) end def teardown $foo = nil end After four test methods are called, ObjectSpace still holds two objects of class Foo, although the code only has that one variable for the one instance of Foo needed. Is this a quirk of Test::Unit? Or of ObjectSpace? I've tried adding a call to ObjectSpace.garbage_collect before the iteration, but it doesn't change anything. This appears to be a Test::Unit quirk because if I call the code outside of the Test::Unit::TestCase subclass then I find no leftover objects. Direct calls to setup and teardown do not leave any objects around, and the call to each_object finds the one item that should be there. How can I ensure that once teardown is called that there are no extra objects lingering in ObjectSpace, short of doing the setup and teardown by hand inside of each test method? I'm using ruby 1.8.0 (2003-05-26) [i386-mswin32] and whatever Test::Unit that comes with that (there's no version number in unit.rb) Thanks, James Britt