[Patches] [Patch #102925] Add new function gc.getreferents

noreply@sourceforge.net noreply@sourceforge.net
Tue, 19 Dec 2000 16:56:49 -0800


Patch #102925 has been updated. 

Project: python
Category: core (C code)
Status: Open
Submitted by: loewis
Assigned to : nascheme
Summary: Add new function gc.getreferents

Follow-Ups:

Date: 2000-Dec-19 14:52
By: loewis

Comment:
Even though the function does not find all references to an object, it does find all objects that have references to some object - at least if all container types participate in garbage collection (I expect that most extension types will know about GC sooner or later).
In particular, it finds containers that can't be found from pure Python, eg. containers that are stored only in a global variable of some C module. Even not being able to explain all references to some object gives a useful clue.

I agree that exposing traversal to Python is a useful feature, but that is completely different from that function - you'd also need to expose the generations lists (which this patch does access, but pure Python can't).
-------------------------------------------------------

Date: 2000-Dec-19 11:25
By: nascheme

Comment:
I'm -0 on this patch. The function is not as useful as it seems.  The
garbage collector does not and most likely never will be able to track
down all references to an object (eg. an extension types could have a
reference to it).  If it could, we would be using a different
collection scheme like mark and sweep.

For debugging reference cycles like the RExec problem a pure Python
tool (similar to Cyclops) would work.  The tool just has
to know how to chase references in different kinds of
objects.  Perhaps exposing the GC's knowledge of this
would be more useful and general.
-------------------------------------------------------

Date: 2000-Dec-19 07:13
By: loewis

Comment:
This patch adds a new function gc.getreferents which traverses all collectable objects and returns a list of objects that refer to any of the parameters of gc.getreferents.
This will only find references visible to the gc; references in local variables of functions that are currently on the stack won't be found.
-------------------------------------------------------

-------------------------------------------------------
For more info, visit:

http://sourceforge.net/patch/?func=detailpatch&patch_id=102925&group_id=5470