Peter Otten __peter__ at
Mon Aug 9 18:31:07 CEST 2010

daryn wrote:

> I'm just playing around with the iter function and I realize that I
> can use the iterator returned by it long after the original object has
> any name bound to it.  Example:
> 1
>>>>del a
> 99
> 3
> 101
> it seems as if the original object is never being garbage collected
> even though there is no name bound to it.  Does the name bound to the
> iterator object count as a reference to the original object for
> garbage collection purposes?  

The listiterator object internally holds a reference to the list, but 
doesn't make it available to Python code.

> Is there some way to retrieve/manipulate
> the original object via the iterator?

Not without dirty tricks (ctypes).
> Just trying to understand how this all works.

If you can read C look here:


More information about the Python-list mailing list