Debugging GC


(Joel VanderWerf) #1

Hi.
I’ve been debugging memory problems in a ruby app lately, and I needed
to know why certain objects were not collected. So I patched gc.c and
memory.c to add a method to the GC module that accepts an object and
returns an array of arrays, each of which represents a path from root
references (stack, globals, etc.) up to (but not including) your object.
It’s fairly useful, but limited. Unfortunately, this functionality
cannot be easily implemented as an extension, only as a patch, because
hardcoded calls to rb_gc_mark are all over the place, and there is no
way to customize the behavior of rb_gc_mark. Anyway, it’s at:

http://redshift.sourceforge.net/debugging-GC/

Hope it’s useful to someone besides me…


(Paul Brannan) #2

I’ve been wanting something like this for quite some time. It’s not
easy to test to make sure you aren’t keeping references to objects you
don’t intend to keep references to; this sounds like it should
definitely help.

Do you have a patched gc.c that works with Ruby 1.7?

Paul

···

On Mon, Jun 17, 2002 at 06:08:20AM +0900, Joel VanderWerf wrote:

Hope it’s useful to someone besides me…


(Joel VanderWerf) #3

Paul Brannan wrote:

Hope it’s useful to someone besides me…

I’ve been wanting something like this for quite some time. It’s not
easy to test to make sure you aren’t keeping references to objects you
don’t intend to keep references to; this sounds like it should
definitely help.

Do you have a patched gc.c that works with Ruby 1.7?

No, sorry. I’ve never looked into 1.7, but it might not be too hard to
adapt. The patch consists of a small change in variable.c plus a new
method in gc.c plus a few lines added or changed in rc_gc_mark(). Look
for the ‘#ifdef DEBUG_REACHABILITY’, and let me know if I can help with
anything.

···

On Mon, Jun 17, 2002 at 06:08:20AM +0900, Joel VanderWerf wrote:


(Joel VanderWerf) #4

Paul Brannan wrote:

Do you have a patched gc.c that works with Ruby 1.7?

It works for 1.7.2, now. See
http://redshift.sourceforge.net/debugging-GC/