Ruby/Development/GC

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

(Различия между версиями)
Перейти к: навигация, поиск
м (1 версия: Импорт выборки материалов по Ruby)
 

Текущая версия на 17:55, 13 сентября 2010

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