classification
Title: ABC caches should use weak refs
Type:
Components: Interpreter Core Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, pitrou
Priority: Keywords: 26backport

Created on 2008-03-31 15:12 by amaury.forgeotdarc, last changed 2008-05-07 11:35 by pitrou.

Messages
msg64784 (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) Date: 2008-03-31 15:12
The following function seems to 8 references each time it is run:

import io, gc
def f():
   class C: pass
   c=C()
   assert isinstance(c, io.StringIO) is False
   gc.collect();gc.collect();gc.collect()


This is because io.StringIO._abc_negative_cache contains a strong
reference to each "class C", as soon as isinstance() is called. These
are never released.

Python3.0 does use WeakSet for these caches, and does not leak.
This is the (deep) reason why test_io.IOTest.test_destructor() leaks in
the following report:
http://mail.python.org/pipermail/python-checkins/2008-March/067918.html
(The test derives from io.FileIO, and it is the call to the base class'
method which calls isinstance() and put the class in the cache)
History
Date User Action Args
2008-05-07 11:35:15pitrousetnosy: + pitrou
2008-03-31 15:12:29amaury.forgeotdarccreate