mgedmin / objgraph

Visually explore Python object graphs
http://mg.pov.lt/objgraph/
MIT License
753 stars 72 forks source link

show_chain shouldn't stop at modules that aren't in sys.modules #1

Closed gavinwahl closed 10 years ago

gavinwahl commented 10 years ago

A module shouldn't be considered a gc root unless it's actually in sys.modules.

Should the examples be updated to use the new is_root function instead of inspect.ismodule?

mgedmin commented 10 years ago

Thanks!

Excellent, but I think 'is_root' is a misleading name for this function. I haven't actually looked at the CPython sources, but I'm pretty sure the GC has more roots than just sys.modules (e.g. the stack frame of the currently executing function).

How about naming it 'is_proper_module' or something? Or maybe just 'is_module'.

And yes, the examples can be updated.

gavinwahl commented 10 years ago

I did some research about what the gc roots actually are in cpython, and it turns out it doesn't have this concept at all! Here is a good article about the algorithm: http://www.arctrix.com/nas/python/gc/ (despite being a decade old, it's still accurate). Also a post from Guido: http://mail.python.org/pipermail/python-dev/2000-March/002385.html.

Anyway, I'll rename the function and update the examples.

mgedmin commented 10 years ago

Thanks for the links, very interesting reading!

mgedmin commented 10 years ago

There's also a StackOverflow question that links to the relevant CPython source code bits.

gavinwahl commented 10 years ago

I updated the patch

mgedmin commented 10 years ago

Thanks, merged.