When would you use this garbage collection method in your Ruby program(s)?
GC.start
I'm benchmarking some code that creates a lot of objects, and I noticed that my benchmarks vary wildly. I determined that the spikes were from garbage collection running during my benchmark.
Controlling the process manually gives me more consistent benchmarks.
def without_gc
GC.start # start out clean
GC.disable
begin
yield
ensure
GC.enable
end
end
without_gc do
Benchmark.measure { some_code }
end
That said, GC.start will cause significant slowdowns if you run it repeatedly.