<br><br><div><span class="gmail_quote">On 8/30/07, <b class="gmail_sendername">&quot;Martin v. Löwis&quot;</b> &lt;<a href="mailto:martin@v.loewis.de">martin@v.loewis.de</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&gt; I tried recreating the leak with more controllable types, but I haven&#39;t<br>&gt; got very far. It seems to be caused by some weird interaction between<br>&gt; io.FileIO, _fileio._FileIO and io.IOBase, specifically 
io.IOBase.__del_<br>&gt; _() calling self.close(), and io.FileIO.close() calling<br>&gt; _fileio._FileIO.close() *and* io.RawIOBase.close(). The weird thing is<br>&gt; that the contents of RawIOBase.close() doesn&#39;t matter. The mere act of
<br>&gt; calling RawBaseIO.close (self) causes the leak. Remove the call, or<br>&gt; change it into an attribute fetch, and the leak is gone. I&#39;m stumped.<br><br>I think the problem is that the class remains referenced in
<br>io.RawIOBase._abc_cache:<br><br>py&gt; io.RawIOBase._abc_cache<br>set()<br>py&gt; class f(io.RawIOBase):pass<br>...<br>py&gt; isinstance(f(), io.RawIOBase)<br>True<br>py&gt; io.RawIOBase._abc_cache<br>{&lt;class &#39;__main__.f&#39;&gt;}
<br>py&gt; del f<br>py&gt; io.RawIOBase._abc_cache<br>{&lt;class &#39;__main__.f&#39;&gt;}<br><br>Each time test_destructor is called, another class will be added to<br>_abc_cache.</blockquote><div><br>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&#39;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.
<br></div></div><br>-- <br>Thomas Wouters &lt;<a href="mailto:thomas@python.org">thomas@python.org</a>&gt;<br><br>Hi! I&#39;m a .signature virus! copy me into your .signature file to help me spread!