Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

GC.start

GC.start → nil
ObjectSpace.garbage_collect → nil
include GC; garbage_collect → nil
GC.start(full_mark: true, immediate_sweep: true) → nil
ObjectSpace.garbage_collect(full_mark: true, immediate_sweep: true) → nil
include GC; garbage_collect(full_mark: true, immediate_sweep: true) → nil

Initiates garbage collection, even if manually disabled.

This method is defined with keyword arguments that default to true:

Example
def GC.start(full_mark: true, immediate_sweep: true); end

Use full_mark: false to perform a minor GC. Use immediate_sweep: false to defer sweeping (use lazy sweep).

Note: These keyword arguments are implementation and version dependent. They are not guaranteed to be future-compatible, and may be ignored if the underlying implementation does not support them.