How does Ruby GC maintain correctness during incremental marking?
Updated May 17, 2026
Short answer
Incremental GC uses write barriers and tri-color marking to preserve correctness during partial marking.
Deep explanation
Ruby GC uses tri-color marking (white, gray, black). Objects are gradually marked instead of all at once. Write barriers ensure that mutations during marking do not violate invariants. If a black object references a white object, the barrier promotes it to gray. This prevents premature collection and ensures correctness even while GC runs concurrently with program 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