seniorRuby

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 pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More Ruby interview questions

View all →