seniorRuby
How does Ruby Garbage Collector (GC) decide when to run?
Updated May 17, 2026
Short answer
Ruby GC runs based on heap allocation thresholds and memory pressure heuristics.
Deep explanation
CRuby uses a generational GC (minor and major collections). Objects are allocated in the young generation. When allocation thresholds are exceeded, a minor GC runs. If survivors accumulate or memory pressure increases, major GC is triggered. Incremental marking reduces pause times by spreading work across execution.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro