[Python-3000] refleak in test_io?

Guido van Rossum guido at python.org
Thu Aug 30 15:47:24 CEST 2007


On 8/30/07, Thomas Wouters <thomas at python.org> wrote:
>
>
> On 8/30/07, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> > > 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.
> >
> > I think the problem is that the class remains referenced in
> > io.RawIOBase._abc_cache:
> >
> > py> io.RawIOBase._abc_cache
> > set()
> > py> class f(io.RawIOBase):pass
> > ...
> > py> isinstance(f(), io.RawIOBase)
> > True
> > py> io.RawIOBase._abc_cache
> > {<class '__main__.f'>}
> > py> del f
> > py> io.RawIOBase._abc_cache
> > {<class '__main__.f'>}
> >
> > Each time test_destructor is called, another class will be added to
> > _abc_cache.
>
> Ahh, thanks, I missed that cache. After browsing the code a bit it seems to
> me the _abc_cache and _abc_negative_cache need to be turned into weak sets.
> (Since a class can appear in any number of caches, positive and negative, we
> can't just check refcounts on the items in the caches.) Do we have a weak
> set implementation anywhere yet? I think I have one lying around I wrote for
> someone else a while back, it could be added to the weakref module.

It should be made into weak refs indeed. Post 3.0a1 I suspect. I'll
add an issue so we won't forget.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list