Why local_variables
printing the name of local variables,while it has
been garbage collected?
require ‘weakref’
a = “abc”
p local_variables
p defined? a
p a.to_s
a = WeakRef.new(a)
p GC.enable
GC.start
p local_variables
p defined? a
p a.to_s
Output:
[:a]
“local-variable”
“abc”
false
[:a]
“local-variable”
true.rb:253:in `’: Invalid Reference - probably recycled
(WeakRef::RefError)