mem_inspect is ObjectSpace.each_object on crack. mem_inspect gives you the contents of each slot in Ruby's heap. mem_inspect also includes viewers that let you visualize the contents of Ruby's heap.

Installing mem_inspect

First, install the gem:

$ sudo gem install mem_inspect

Then you need to build a patched ruby:


Optionally, you can install the patch ruby binary. It will be named “ruby_mem_inspect”.

Using mem_inspect

Dumping a PNG

To get a PNG of memory use:

mem_inspect_ruby_1_8/ruby_mem_inspect -S ruby_mem_dump

To get a PNG of memory use in your application:

require 'mem_inspect'
require 'mem_inspect/png_viewer'

And when you want to dump a PNG:, 768).draw

Dumping via AquaTerm

First you'll need to install RubyCocoa. You can find instructions for that here:

Then you'll need to download AquaTerm:

Once you have all that installed you can dump to an AquaTerm plot:

require 'mem_inspect'
require 'mem_inspect/aquaterm_viewer'

And when you want a plot:, 768).draw