Closed gavinwahl closed 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.
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.
Thanks for the links, very interesting reading!
There's also a StackOverflow question that links to the relevant CPython source code bits.
I updated the patch
Thanks, merged.
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 ofinspect.ismodule
?