Memory profiling is harder than CPU profiling (mostly because the tools are immature), but it can reveal more severe slowdowns. The more you use memory, the more time your program spends in garbage collection.
You can use ruby-prof and KCachegrind tools for memory profiling, but you need to run a patched Ruby. Fortunately, it’s easy to do so with rbenv and rvm.
Remember the little details that can make your profiles invalid. Turn off GC for CPU profiling, but leave it on for memory profiling, especially GC calls/time profiling.
Don’t use current memory usage and GC statistics for memory profiling unless you have no other choice. Those numbers are a function of current program state and GC settings; they aren’t repeatable in production. ...