This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Cycles with some iterator are leaking.
Type: Stage:
Components: Interpreter Core Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, jcea, loewis, pitrou, schuppenies
Priority: normal Keywords: patch

Created on 2008-08-25 20:43 by schuppenies, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cycle.py schuppenies, 2008-08-25 20:43 demonstrates the problem for dict iterators
tp_traverse.patch schuppenies, 2008-08-25 20:45 Patch against 2.6 trunk, revision 66031
Messages (4)
msg71955 - (view) Author: Robert Schuppenies (schuppenies) * (Python committer) Date: 2008-08-25 20:43
The dict, set, and deque iterators do not implement tp_traverse although
they reference container objects. This can lead to reference cycles
which will not be collected. The attached cycle.py script from Amaury
demonstrates the problem for dict iterators. The attached patch
addresses the issue for the above mentioned types. The method applied in
the demonstration script was used for test cases.

This is my first excursion into cyclic garbage collector
implementations, so please review carefully. Also, I am not sure about
tp_traverse for the deque type. Must the block member also be considered
or is the deque member sufficient?

Finally, do you consider this a show stopper?
msg72741 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-09-07 16:16
> This is my first excursion into cyclic garbage collector
> implementations, so please review carefully.

If you don't implement a tp_clear function, you should leave
a comment why not. I think it's ok, since the underlying
containers will get cleared, thus breaking the cycle.

> Also, I am not sure about
> tp_traverse for the deque type. Must the block member also be considered
> or is the deque member sufficient?

It is fine as-is. The iterator doesn't own the reference to the block
objects, and traversing the deque will also traverse all contained
objects.

> Finally, do you consider this a show stopper?

Not me. As-is, this bug doesn't cause crashes, and can be worked-around
in applications (by explicitly breaking the cycle).
msg73222 - (view) Author: Robert Schuppenies (schuppenies) * (Python committer) Date: 2008-09-14 13:27
> I think it's ok, since the underlying containers will get cleared, thus
> breaking the cycle.

What about the dictiter object which references a tuple (di_result)?
Tuple does not implement tp_clear, but OTOH tuples are immutable and
di_result cannot be assigned.
msg78713 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-01-01 15:39
Committed to trunk and py3k, thanks!
History
Date User Action Args
2022-04-11 14:56:38adminsetgithub: 47930
2009-01-01 15:39:57pitrousetstatus: open -> closed
resolution: fixed
messages: + msg78713
2009-01-01 02:28:07pitrousetnosy: + pitrou
2008-09-14 13:27:38schuppeniessetmessages: + msg73222
2008-09-07 16:16:02loewissetnosy: + loewis
messages: + msg72741
title: Cycles with some iterator are leaking. -> Cycles with some iterator are leaking.
2008-08-28 18:25:45jceasetnosy: + jcea
2008-08-25 20:45:04schuppeniessetfiles: + tp_traverse.patch
2008-08-25 20:43:45schuppeniescreate