I don't understand. Are you saying there's a temporary reference to the
class? I was asking why that would be the case when I define a class one
way, but not another?
This code does NOT remove the class Foo:
class Foo; end
Object.module_eval { remove_const 'Foo' }
GC.start
But this DOES remove it:
eval 'class Foo; end'
Object.module_eval { remove_const 'Foo' }
GC.start
To sum up all the ways of defining a class I can think of, the following
ways of defining a class WILL allow the class to be removed (at least by
removing the constant and starting the GC):
--> eval 'class Foo; end'
--> Foo = Class.new
--> load 'foo.rb'
--> require 'foo.rb'
(foo.rb is simply: class Foo; end)
And the following WILL NOT allow the class to be removed:
--> class Foo; end
--> eval 'Foo = Class.new' # How weird is that??
So I just wanted to know why. If you are saying there's a temporary
reference, why is it avoided by using 'eval' (or sometimes *caused* by using
'eval')? Is there a way I can get rid of this temporary reference?
Chris