On this page
End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
GC
The GC module provides an interface to Ruby’s mark and sweep garbage collection mechanism.
Some of the underlying methods are also available via the ObjectSpace module.
You may obtain information about the operation of the GC through GC::Profiler.
Class methods 24
Instance methods 1
internal constants
GC build options
Ruby version changes 4
-
3.2
-
Expose
need_major_gcviaGC.latest_gc_info. GH-6791
-
-
3.1
-
“GC.measure_total_time = true” enables the measurement of
GC. Measurement can introduce overhead. It is enabled by default.GC.measure_total_timereturns the current setting.GC.stat[:time] orGC.stat(:time) returns measured time in milli-seconds. [[Feature #10917]] -
GC.total_timereturns measured time in nano-seconds. [[Feature #10917]]
-
-
3.0
-
GC.auto_compact=andGC.auto_compacthave been added to control when compaction runs. Settingauto_compact=to true will cause compaction to occur during major collections. At the moment, compaction adds significant overhead to major collections, so please test first! [Feature #17176]
-