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 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