I'am trying to figure out ObjectSpace.each_object
In console:
class Foo; end
Foo.new
ObjectSpace.each_object(Foo).count
=> 1
GC.start
ObjectSpace.each_object(Foo).count
=> 1
I've seen examples and I know that the second count should be 0.
Any ideas what is going on here?
Thanks.
It depends on your console.
IRB
The last result is saved as
_
, even if it hasn't been explicitely assigned. RunningGC.start
won't remove the last object :Pry
You can access the last result and the second to last result with
_
and__
:Pry saves all the 100 last results in
_out_
Pry::HistoryArray:You can use
_out_.pop!
to remove its last element :Inside a script
If you execute :
inside a script, you get :