seniorRuby

How does Ruby manage object graph reachability from root set?

Updated May 17, 2026

Short answer

GC starts from root set (stack, globals, constants) and marks all reachable objects.

Deep explanation

The root set includes VM stack frames, global variables, class variables, and constants. GC begins marking from these roots, recursively traversing references. Any object not reachable is considered garbage. This ensures only live objects remain while cyclic but unreachable graphs are collected safely.

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 →