Memory Leaks: How to see GC Roots?

  • Thread starter Sven C. Koehler
  • Start date
S

Sven C. Koehler

Hello!

Is there a way to get a list of all GC roots in my Ruby program? I know
there is a memory leak somewhere in my application, I just don't know in
which part. Listing all variables on the Heap becomes too large, but just
seeing the GC roots would be a great help. Can you suggest some ideas?

Best wishes,

Sven C. Koehler
 
R

Robert Klemme

Sven said:
Hello!

Is there a way to get a list of all GC roots in my Ruby program? I
know there is a memory leak somewhere in my application, I just don't
know in which part. Listing all variables on the Heap becomes too
large, but just seeing the GC roots would be a great help. Can you
suggest some ideas?

I don't think this info is available. But how about statistics per class?
That way you can at least determine which class is responsible for the
massive object count.

17:09:39 [source]: ruby -r pp -e 'c=Hash.new(0); ObjectSpace.each_object
{|obj| c[obj.class]+=1}; pp c.sort_by {|k,v| -v}'
[[String, 582],
[Class, 185],
[Module, 18],
[Array, 8],
[Float, 6],
[Regexp, 6],
[Object, 3],
[IO, 3],
[File, 2],
[NoMemoryError, 1],
[SystemStackError, 1],
[Binding, 1],
[fatal, 1],
[ThreadGroup, 1],
[Hash, 1],
[Thread, 1]]

Kind regards

robert
 
J

Joel VanderWerf

Sven said:
Hello!

Is there a way to get a list of all GC roots in my Ruby program? I know
there is a memory leak somewhere in my application, I just don't know in
which part. Listing all variables on the Heap becomes too large, but just
seeing the GC roots would be a great help. Can you suggest some ideas?

Best wishes,

Sven C. Koehler

There's a ruby patch to show what objects are reachable from the roots
(and the chain of references in each case):

http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/151854?151368-152549

It should easy to modify it to just show the roots.
 
S

Sven C. Koehler

There's a ruby patch to show what objects are reachable from the roots
(and the chain of references in each case):

http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/151854?151368-152549

It should easy to modify it to just show the roots.

I tried to use the patch with Ruby 1.8.3 and the current CVS Trunk
snapshot as of today (2005-12-02). With Ruby 1.8.3 I had to adjust the
rb_sprintf calls to use snprintf. In order to use the patch with the
current Trunk, I had to apply part of the patch by hand. However, I got
no usable output by trying to use it on both versions, so I don't know
whether the patch is actually able to access the GC roots.

The output looks on both ruby 1.8.3 and the CVS Trunk as this:

irb(main):001:0> $a = File.open("fo", "w")
=> #<File:fo>
irb(main):002:0> $b = [$a]
=> [#<File:fo>]
irb(main):003:0> GC.reachability_paths($a)
(irb):3: warning: Checking frame stack...
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: Checking ruby_class...
(irb):3: warning: Checking ruby_scope...
(irb):3: warning: Checking save_regs_gc_mark...
(irb):3: warning: Checking stack_start...
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: Checking threads...
(irb):3: warning: Checking C globals...
(irb):3: warning: Checking end_proc...
(irb):3: warning: Checking global_tbl...
(irb):3: warning: Checking class_tbl...
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: Checking trap_list...
(irb):3: warning: Checking generic_ivar_tbl...
(irb):3: warning: Checking mark parser...
(irb):3: warning: Checking mark stack...
(irb):3: warning: Unmarking...
(irb):3: warning: Done.
=> [[], [], [], [], [], [], [], [], [], [], []]


I would have expected $a to be reachable via $b.

Best wishes,

Sven C. Koehler
 
S

Stephen Kellett

Sven C. Koehler said:
Is there a way to get a list of all GC roots in my Ruby program? I know
there is a memory leak somewhere in my application, I just don't know in
which part. Listing all variables on the Heap becomes too large, but just
seeing the GC roots would be a great help. Can you suggest some ideas?

If you are on Windows then Ruby Memory Validator can do this.

http://www.softwareverify.com

Stephen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

memprof / GC dynamics 1
Debugging memory leaks 20
[Q] WIN32OLE memory leaks 20
Memory leaks, maybe. need help. 2
memory manager to prevent memory leaks 4
pthread memory leaks 15
Memory leaks 2
Zipimport leaks memory? 0

Members online

Forum statistics

Threads
474,197
Messages
2,571,041
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top