Issue 3680: Cycles with some iterator are leaking. (original) (raw)

Issue3680

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:38 admin set github: 47930
2009-01-01 15:39:57 pitrou set status: open -> closedresolution: fixedmessages: +
2009-01-01 02:28:07 pitrou set nosy: + pitrou
2008-09-14 13:27:38 schuppenies set messages: +
2008-09-07 16:16:02 loewis set nosy: + loewismessages: + title: Cycles with some iterator are leaking. -> Cycles with some iterator are leaking.
2008-08-28 18:25:45 jcea set nosy: + jcea
2008-08-25 20:45:04 schuppenies set files: + tp_traverse.patch
2008-08-25 20:43:45 schuppenies create