Ruby belleği otomatik olarak artık referans edilmeyen nesneleri geri kazanan bir çöp toplayıcı (GC) aracılığıyla yönetir. Modern Ruby (MRI) jenerasyonel, artan mark-and-sweep toplayıcısını sıkıştırma ile kullanır. Bunu anlamak, performans ve uzun süren uygulamalarda bellek sorunlarını teşhis etmeye yardımcı olur.
Otomatik çöp toplama
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
