Call GC to do a garbage collection : GC « Development « Ruby






Call GC to do a garbage collection


a = "hello"
puts "'hello's object id is #{a.id}"
ObjectSpace.define_finalizer(a) { |id| puts "Destroying #{id}" }
GC.start
a = nil
puts "The original string is now a candidate for collection"
GC.start

 








Related examples in the same category

1.Disabling the Garbage Collector