From: Larsenmtl Larsenmtl Date: 2008-08-07T23:10:32+09:00 Subject: Array Of Objects, Removing Element From Memory Ruby Fans, I'm having trouble understanding when Ruby GC kicks in for Object instances that are no longer referred to by anything. A simple code sample to illustrate: [CODE] class TestClass end collection = [] collection << TestClass.new collection << TestClass.new collection << TestClass.new collection << TestClass.new numTC = 0 ObjectSpace.each_object{|obj| numTC += 1 if obj.class == TestClass } puts numTC collection.delete_at(0) collection.delete_at(0) collection.delete_at(0) collection.delete_at(0) numTC = 0 ObjectSpace.each_object{|obj| numTC += 1 if obj.class == TestClass } puts numTC [/CODE] If you run this you'll see that 4 TestClass instances are still in the ObjectSpace even after they are deleted from the collection array. I tried manually calling the garbage collector after deleting the elements from the array but I get the same result. How do I get Ruby to trash those instances? Thanks, Mark -- Posted via http://www.ruby-forum.com/.