[Python-3000] refleak in test_io?
Thomas Wouters
thomas at python.org
Thu Aug 30 01:56:53 CEST 2007
Am I the only one seeing a refleak in test_io?
timberwolf:~/python/python/py3k > ./python -E -tt Lib/test/regrtest.py -R::
test_io
test_io
beginning 9 repetitions
123456789
.........
test_io leaked [62, 62, 62, 62] references, sum=248
1 test OK.
It's in this particular piece of code:
def test_destructor(self):
record = []
class MyFileIO(io.FileIO):
def __del__(self):
record.append(1)
io.FileIO.__del__(self)
def close(self):
record.append(2)
io.FileIO.close(self)
def flush(self):
record.append(3)
io.FileIO.flush(self)
f = MyFileIO(test_support.TESTFN, "w")
f.write("xxx")
del f
self.assertEqual(record, [1, 2, 3])
which you can simplify to:
def test_destructor(self):
class MyFileIO(io.FileIO):
pass
f = MyFileIO(test_support.TESTFN, "w")
del f
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.
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.
--
Thomas Wouters <thomas at python.org>
Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20070830/39925414/attachment.htm
More information about the Python-3000
mailing list