<br>Am I the only one seeing a refleak in test_io?<br><br>timberwolf:~/python/python/py3k > ./python -E -tt Lib/test/regrtest.py -R:: test_io<br>test_io<br>beginning 9 repetitions<br>123456789<br>.........<br>test_io leaked [62, 62, 62, 62] references, sum=248
<br>1 test OK.<br><br>It's in this particular piece of code:<br><br> def test_destructor(self):<br> record = <br> class MyFileIO(io.FileIO):<br> def __del__(self):<br> record.append
(1)<br> io.FileIO.__del__(self)<br> def close(self):<br> record.append(2)<br> io.FileIO.close(self)<br> def flush(self):<br> record.append(3)
<br> io.FileIO.flush(self)<br> f = MyFileIO(test_support.TESTFN, "w")<br> f.write("xxx")<br> del f<br> self.assertEqual(record, [1, 2, 3])<br><br>which you can simplify to:
<br><br> def test_destructor(self):<br> class MyFileIO(io.FileIO):<br> pass<br> f = MyFileIO(test_support.TESTFN, "w")<br> del f<br><br>That leaks 30 references each time it's called. Taking the class definition out of the function stops the leak, so it smells like something, somewhere, is leaking a reference to the MyFileIO class, Instantiating the class is necessary to trigger the leak: the refcount of the class goes up after creating the instance, but does not go down after it's destroyed. However, creating and destroying another instance does not leak another reference, only the single reference is leaked.
<br><br>I tried recreating the leak with more controllable types, but I haven't got very far. It seems to be caused by some weird interaction between io.FileIO, _fileio._FileIO and io.IOBase, specifically io.IOBase.__del_
_() calling self.close(), and io.FileIO.close() calling _fileio._FileIO.close() *and* io.RawIOBase.close(). The weird thing is that the contents of RawIOBase.close() doesn't matter. The mere act of calling RawBaseIO.close
(self) causes the leak. Remove the call, or change it into an attribute fetch, and the leak is gone. I'm stumped.<br><br>-- <br>Thomas Wouters <<a href="mailto:firstname.lastname@example.org">email@example.com</a>><br><br>Hi! I'm a .signature virus! copy me into your .signature file to help me spread!