Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

GC.stress=

(::Integer flag) -> ::Integer
(bool flag) -> bool
GC.stress = value → value

Enables or disables stress mode. Stress mode causes GC to be invoked at every GC opportunity (all memory and object allocations); it is intended only for debugging and severely degrades performance.

Sets the current GC stress mode to the given value:

  • If the value is nil or false, disables stress mode.

  • If the value is an integer, enables stress mode with certain flags; see below.

  • Otherwise, enables stress mode without any flags.

The flags are bits in the given integer:

  • 0x01: no major GC.

  • 0x02: no immediate sweep.

  • 0x04: full mark after malloc/calloc/realloc.