Python 2.0

Michael Hudson mwh21 at cam.ac.uk
Tue Jun 1 05:54:32 EDT 1999


"Stidolph, David" <stidolph at origin.ea.com> writes:

> >OK, I'll try to propose something constructive. Maybe we need an object
> >protocol, that would enumerate
> >all references held by an object ?  Writing a portable GC would be then
> much
> >easier.
> 
> Sounds good to me for debugging.  A call that could return a list of
> everything that holds a reference to an object - that would be cool!
> 
> list = GetReferences(object)
> print 'List of referencest to',object
> for item in list:
>   print 'item:',item
> 
> Anybody know of a current way to do this?

If you recompile Python with Py_TRACE_REFS defined, then the sys
module sprouts a "getobjects" function that returns a list of all
objects in existence. This could probably be used to implement
something like this. It would be veeeeery slow, I suspect.

I've never resorted to this approach, tending always to make cyclic
references go away be staring at them very, very hard.

I'm not sure this is at all what is being asked for, but it seems kind
of relavent.

Yours,
Michael




More information about the Python-list mailing list