From: Kent Dahl Date: 2003-08-01T17:28:08+09:00 Subject: Re: Test::Unit leaving phanthom objects in ObjectSpace? james_b wrote: > 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. [snip] > 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. [snip] > 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) I cannot reproduce it using ruby 1.8.0 (2003-07-24) [i686-linux], so perhaps it was a temporary problem that has been fixed. Suggest you try a newer version to see if it helps. [kentda@localhost ruby]$ ruby1.8 -v setup.rb ruby 1.8.0 (2003-07-24) [i686-linux] Loaded suite ATest Started ..... Finished in 0.003337 seconds. 4 tests, 0 assertions, 0 failures, 0 errors Foos:4 Foos:0 [kentda@localhost ruby]$ cat setup.rb require 'test/unit' class Foo end class ATest < Test::Unit::TestCase def setup $foo = Foo.new end def teardown $foo = nil end def test_a; end def test_b; end def test_c; end def test_d; end end def num_foos n = 0 ObjectSpace.each_object(Foo){|i| n+=1 } print "Foos:", n, "\n" end if __FILE__ == $0 require 'test/unit/ui/console/testrunner' Test::Unit::UI::Console::TestRunner.run ATest.suite num_foos ObjectSpace.garbage_collect num_foos end -- (\[ Kent Dahl ]/)_ _~_ _____[ http://www.pvv.org/~kentda/ ]_____/~ ))\_student_/(( \__d L b__/ (pre-) Master of Science in Technology ) ( \__\_�|�_/__/ ) _)Industrial economics and technological management( \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___)