From: Florian Weber Date: 2005-10-22T03:09:57+09:00 Subject: Re: Removing a class for good from ObjectSpace > Your test looks odd to me. First you create Foo. Next you destroy it with > remove_const and const_set, but the class you set Foo to also inherits from > Bar. The next section of code has no effect, because Foo already > exists. Lastly you check to see if there are any classes that inherit > from Bar, which will of course be true, because Foo still inherits from > Bar. Yup, but I want that only one Foo class inheriting from Bar is found in the ObjectSpace. Not two. My example above finds two classes named Foo. The original one and the one created using Class.new. Can you think of any way around that? To completely remove the old version and make only the new one, the one created via Class.new, available in the ObjectSpace > Your other problem is that the original Foo class is probably still on > the stack, and the GC is picking that up. So here's a fixed test: > > class Bar > end > > def create_Foo(n=1000) > return create_Foo(n-1) if n > 0 > eval "class Foo < Bar; end" > end > create_Foo > > Object.class_eval do > remove_const :Foo > const_set :Foo, Class.new > end > GC.start > > ObjectSpace.each_object(Class) do |klass| > puts klass if Bar > klass > end Ah! cool! thanks! that works. But unfortunately I can't use it like that. the original class definition is done in another way, I can't do it with eval and/or inside a method. Can you think of any other ways? Thanks a lot!