These slides by Joe Damato and Aman Gupta explain Garbage Collection and the Ruby Heap really well.
It talks about the following:
- How memory is managed in Ruby vs C
- All variables and all ruby code lives on the heap like any other object
- In ruby there’s no way to explicitly free memory
- How the garbage collection works in the ruby interpreter (MRI)
- How ruby finds garbage to determine what can be freed up
- No Ruby code can run while GC is running
- The mark and sweep phase
- Memprof (Memory Profiler which allows you to debug memory issues) and how they used it to find a 10mb per request memory leak in Rails 3
If you want to debug memory issues, use Memprof.
gem install memprof memprof YOUR_RAILS_APP_PID
Leave a Reply