From: Aristarkh A Zagorodnikov Date: 2001-10-09T19:47:14+09:00 Subject: [ruby-talk:22295] Possible GC bug? Hello! While trying to find out why my ruby program has memory leaks I found. Consider the following code: class A def initialize @a = 123 end def finalize for variable in instance_variables do remove_instance_variable variable end end end # Create object f = A.new # Finalize it f.finalize # Remove reference f = nil # Start GC to be sure GC.start # Check all objects (dirty hack checks) ObjectSpace.each_object do |object| p object if object.is_a? Array and object.size == 1 end Here is the output: xm@is:/home/xm$ ruby gc-test.rb ["@a"] The ["@a"] is f#instance_variables, which dows not get garbage collected. If I replace the 'for' iterator with 'each' one: instance_variables.do |variable| remove_instance_variable variable end or place just any code after the iterator ('for' one) everything is okay. It seems that 'for' iterator which does not create new context prevents garbage collector from behaving correctly in such cases. Aristarkh A Zagorodnikov, Tech Lead @ bolotov.ru group www.bolotov.ru | xm@bolotov-team.ru | ICQ UIN 36987938