Ruby స్వయంచాలకంగా చెత్త సంగ్రహణ (GC) ద్వారా మెమరీని నిర్వహిస్తుంది, ఇది ఇకపై సూచించబడని వస్తువులను తిరిగి సంగ్రహిస్తుంది. ఆధునిక Ruby (MRI) తరం, వృద్ధిశీల చిహ్నం-మరియు-స్వీప్ సంగ్రాహకాన్ని సంపీడనంతో ఉపయోగిస్తుంది. దీన్ని అర్థం చేసుకోవడం పనితీరు మరియు దీర్ఘకాల అనువర్తనాలలో మెమరీ సమస్యలను నిర్ధారించడంలో సహాయపడుతుంది.
స్వయంచాలక చెత్త సంగ్రహణ
Ruby allocates objects on the heap; the GC reclaims those that are no longer REACHABLE
(referenced). You never free memory manually.
Modern MRI GC characteristics:
✓ Mark-and-sweep — marks reachable objects (from roots), sweeps unreachable ones
✓ Generational (since Ruby 2.1) — new objects collected often, old ones rarely
(based on "most objects die young")
✓ Incremental — spreads GC work to reduce pause times
✓ Compacting (GC.compact, Ruby 2.7+) — reduces memory fragmentation
