Methods of Memory Management in MRI
summary
MRI uses a mark-and-sweep collector that is generational and incremental, with write barriers and a remembered set to avoid missing newly-referenced objects. Ruby allocates 16KB slabs of 40-byte slots, uses tagged pointers for small integers/true/false/nil, and promotes objects after three GCs to promote to older generations. A page-segregation patch groups long-lived objects and reduces Rails heap by 17% smaller heap in tests. Useful tools: GC.stat, GC::Profiler, ObjectSpace.dump_all and undocumented RUBY_GC_* environment tunables.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 5:03Memory basics in Ruby
- 10:35Garbage collection algorithms
- 27:40Allocation algorithms
- 36:57Tagged pointers and hacks
- 38:21Copy-on-write issues
- 40:32Optimizing heap usage
- 43:03GC introspection APIs
- 46:14GC tuning in production








