<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Segment7: Memory Inspector</title>
    <link>http://blog.segment7.net/articles/2006/08/30/memory-inspector</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>The Blog</description>
    <item>
      <title>Memory Inspector</title>
      <description>&lt;p&gt;I've hacked into gc.c and added an alternative to &lt;code&gt;ObjectSpace.each_object&lt;/code&gt; that gives you the contents of every heap slot in Ruby's memory space.

&lt;pre&gt;&lt;samp&gt;$ ./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                                           #&amp;lt;Class:Marshal&amp;gt;
0x001caa34 0x00000014                                                    :__node
0x001caa48 0x00000014                                                    :__node
0x001caa5c 0x0000000c                                                    Marshal
[but there's things like nodes, singleton classes, modules,]
0x001caae8 0x0000000c                #&amp;lt;NoMemoryError: failed to allocate memory&amp;gt;
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]&lt;/samp&gt;&lt;/pre&gt;

&lt;p&gt;It requires a hack to gc.c to gain access to the heap, but combined with &lt;a href="http://blog.zenspider.com/archives/2006/08/ruby_memory_vis.html"&gt;Ryan's memory visualizer&lt;/a&gt; this might generate something usable.

&lt;p&gt;Code will be available later I've audited my object size calculations (and have slept).
</description>
      <pubDate>Wed, 30 Aug 2006 01:13:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:78c1d661-ede7-4ac3-9f8f-ab2d520c529e</guid>
      <author>drbrain@segment7.net (Eric Hodel)</author>
      <link>http://blog.segment7.net/articles/2006/08/30/memory-inspector</link>
      <category>Hacking</category>
      <category>Ruby</category>
    </item>
    <item>
      <title>"Memory Inspector" by Eric Hodel</title>
      <description>&lt;p&gt;@David: You could build one simply with &lt;a href="/articles/2006/08/31/mem_inspect-and-png" rel="nofollow"&gt;mem_inspect&lt;/a&gt; which has the size of the objects and everything.  It works similar to ObjectSpace::each_object, but includes (a good guess at) the size of the object.&lt;/p&gt;</description>
      <pubDate>Wed, 13 Sep 2006 09:40:17 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:d48c6073-0240-42e2-ada7-54727357276f</guid>
      <link>http://blog.segment7.net/articles/2006/08/30/memory-inspector#comment-346</link>
    </item>
    <item>
      <title>"Memory Inspector" by David Koe</title>
      <description>&lt;p&gt;Eric,&lt;/p&gt;


	&lt;p&gt;This is great.  Having visibility is the first step towards fixing anything.&lt;/p&gt;


	&lt;p&gt;Do you think it&amp;#8217;s possible to create a module to load into any RoR app to dump out the heap size?&lt;/p&gt;


	&lt;p&gt;Would love to see you code&amp;#8230;&lt;/p&gt;


	&lt;p&gt;Good work.&lt;/p&gt;</description>
      <pubDate>Wed, 13 Sep 2006 09:02:06 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:7380a7d1-1426-49db-88e7-c3160ff6c2a7</guid>
      <link>http://blog.segment7.net/articles/2006/08/30/memory-inspector#comment-345</link>
    </item>
    <item>
      <title>"Memory Inspector" by Pat Eyler</title>
      <description>&lt;p&gt;Wow!  there seems to be a lot of work around the &amp;#8216;Net (and especially in the Seattle.rb) on dealing with Ruby&amp;#8217;s memory.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m hoping more of this stuff gets tied together into nice useable packages to help improve Ruby and our Ruby programs.&lt;/p&gt;


	&lt;p&gt;Thanks for the hard work Eric.&lt;/p&gt;</description>
      <pubDate>Wed, 30 Aug 2006 06:33:42 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:1ea142f1-47cc-44fd-bffc-01bcf45b5ecf</guid>
      <link>http://blog.segment7.net/articles/2006/08/30/memory-inspector#comment-320</link>
    </item>
  </channel>
</rss>
