seniorRuby

What is Ruby’s object lifetime model from allocation to garbage collection?

Updated May 17, 2026

Short answer

Objects go from allocation → young generation → promotion → old generation → GC sweep.

Deep explanation

Ruby allocates objects in young generation heap slots. If they survive GC cycles, they are promoted to old generation. GC periodically marks reachable objects from root set (stack, globals, constants). Unmarked objects are swept and memory reused. This lifecycle optimizes for short-lived objects common in web apps.

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 →