From: Johan Holmberg Date: 2004-09-19T21:17:29+09:00 Subject: Memory-leak --- block/exception related I think I've found a memory leak in recent versions of Ruby (post 1.8.1 versions). It occurs while running "test/unit", but I think it is a problem in the core interpreter. For details see the comments in the testcase file below. /Johan Holmberg ############################################################ # Filename: TC_memory_leak.rb # # Demonstration of yield/block/exception(???) related memory leak. # Run it in the two following ways: # # $ ruby TC_memory_leak.rb --name=test_memory_leak # $ ruby TC_memory_leak.rb --name=test_no_memory_leak # # and note the difference by looking at the Ruby process # with top(1) in another window. The first will "eat" memory. # # The only difference is that "assert_raises" is used in the first case # and "assert_raise" (with no "s") in the second. "assert_raises" is # defined like this: # # def assert_raises(*args, &block) # assert_raise(*args, &block) # end # # For some reason this indirection causes a memory leak. # # Ruby 1.8.1 is not affected. # But both the latest on the "CVS-mainline" and on the "ruby_1_8" branch # seem to be affected by the leak. # require 'test/unit' class TestMemoryLeak < Test::Unit::TestCase def test_memory_leak 10_000_000.times { assert_raises(Errno::ENOENT) { raise Errno::ENOENT } } end def test_no_memory_leak 10_000_000.times { assert_raise(Errno::ENOENT) { raise Errno::ENOENT } } end end ############################################################ # End of TC_memory_leak.rb ############################################################