Ruby/Development/GC

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

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



Disabling the Garbage Collector

h = {}
GC.disable if ARGV[0]
5e5.to_i.times {|i| h[i] = "dummy"}
h = nil
GC.enable
GC.start