Ruby jimexxax il-memorja awtomatikament permezz ta' garbage collector (GC) li jirrikilma oġġetti li m'għadx hemm referenzi għalihom. Ruby modern (MRI) juża generational, incremental mark-and-sweep collector b'compaction. Fehim tiegħu jgħin mal-performance u d-dijanjożi ta' problemi tal-memorja f'applikazzjonijiet li jdumu għal żmien twil.
Garbage collection awtomatiku
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
