I've hacked into gc.c and added an alternative to
ObjectSpace.each_object that gives you the contents of every heap slot in Ruby's memory space.
$ ./ruby -I ~/Work/p4/zss/src/RubyInline/dev/ ~/heapwalk.rb [id, size, inspect] 0x001aa004 0x00000000 :__free 0x001aa018 0x00000000 :__free 0x001aa02c 0x00000000 :__free 0x001aa040 0x00000000 :__free [the beginning is boring...] 0x001caa20 0x00000014 #<Class:Marshal> 0x001caa34 0x00000014 :__node 0x001caa48 0x00000014 :__node 0x001caa5c 0x0000000c Marshal [but there's things like nodes, singleton classes, modules,] 0x001caae8 0x0000000c #<NoMemoryError: failed to allocate memory> 0x001caafc 0x0000002d "failed to allocate memory" 0x001cab10 0x00000014  [exceptions, strings, arrays and other objects,] 0x001ce5f8 0x00000014 :__iclass [included Modules,] 0x001dad30 0x00000014 :__scope [scopes, and some other stuff that's too hard to find]
It requires a hack to gc.c to gain access to the heap, but combined with Ryan's memory visualizer this might generate something usable.
Code will be available later I've audited my object size calculations (and have slept). comments
Comments are disabled