In ruby all classes are objects of class Class. Since classes are also objects, does a Ruby VM follow the same Garbage Collection strategy for class objects? What determines
An even more concrete example, similar to Andrew Cholakian's answer is to use ObjectSpace. For example:
2.1.1 :001 > ObjectSpace.count_objects[:T_CLASS]
=> 884
2.1.1 :002 > 10000.times { Class.new }
=> 10000
2.1.1 :003 > ObjectSpace.count_objects[:T_CLASS]
=> 20884
2.1.1 :004 > GC.start
=> nil
2.1.1 :005 > ObjectSpace.count_objects[:T_CLASS]
=> 884
This shows that anonymous classes (not saved in a constant anywhere or used by any instances of those classes) do indeed get garbage collected.