[Python-bugs-list] [ python-Bugs-633182 ] Memory leak with weakref

noreply@sourceforge.net noreply@sourceforge.net
Mon, 04 Nov 2002 02:02:19 -0800


Bugs item #633182, was opened at 2002-11-04 19:02
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=633182&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: atsuo ishimoto (ishimoto)
Assigned to: Nobody/Anonymous (nobody)
Summary: Memory leak with weakref

Initial Comment:
With Python 2.2.2 on Windows 2000, this code 
leaks 52 bytes of memory for each instance of 
class foo. 

<<code>>
import weakref, sys

class foo:
    def __init__(self):
        self.wref = weakref.WeakValueDictionary()
        self.wref[id(self)] = self

l = [foo() for x in range(int(sys.argv[1]))]

for i in l:
    i.wref.clear()
    del i.wref

del l

import gc
gc.collect()

<<result>>
These reports are printed by msvc's 
_CrtMemDumpStatistics() function.

C:\>python_d a.py 200
Adding parser accelerators ...
Done.
[4504 refs]
0 bytes in 0 Free Blocks.
85405 bytes in 1002 Normal Blocks.
4528 bytes in 15 CRT Blocks.
0 bytes in 0 Ignore Blocks.
0 bytes in 0 Client Blocks.
Largest number used: 556766 bytes.
Total allocations: 1300386 bytes.

C:\>python_d a.py 300
Adding parser accelerators ...
Done.
[4504 refs]
0 bytes in 0 Free Blocks.
95805 bytes in 1202 Normal Blocks.
4528 bytes in 15 CRT Blocks.
0 bytes in 0 Ignore Blocks.
0 bytes in 0 Client Blocks.
Largest number used: 635950 bytes.
Total allocations: 1401070 bytes.


Current cvs version of Python doesn't leak
(with or without PyMalloc).


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=633182&group_id=5470