[issue2246] itertools.groupby() leaks memory with circular reference

Alexander Belopolsky report at bugs.python.org
Thu Mar 6 21:48:10 CET 2008


Alexander Belopolsky added the comment:

With the following patch:

===================================================================
--- Lib/test/test_itertools.py  (revision 61284)
+++ Lib/test/test_itertools.py  (working copy)
@@ -707,6 +707,12 @@
         a = []
         self.makecycle(takewhile(bool, [1, 0, a, a]), a)
 
+    def test_issue2246(self):
+        n = 10
+        keyfunc = lambda x: x
+        for i, j in groupby(xrange(n), key=keyfunc):
+            keyfunc.__dict__.setdefault('x',[]).append(j)
+                    
 def R(seqn):
     'Regular generator'
     for i in seqn:

$ ./python Lib/test/regrtest.py -R :: test_itertools

reports n*3 + 13 reference leaks.  This should give a clue ...

----------
nosy: +belopolsky

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2246>
__________________________________


More information about the Python-bugs-list mailing list