classification
Title: ctypes memory leak
Type: Stage:
Components: ctypes Versions: Python 3.2, Python 3.1, Python 2.7, Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: theller
Priority: normal Keywords: patch

Created on 2010-02-18 21:13 by theller, last changed 2010-02-23 20:33 by theller. This issue is now closed.

Files
File name Uploaded Description Edit
ctypes-leak.py theller, 2010-02-18 21:13 Leaking demo script.
issue7959.patch theller, 2010-02-23 19:46
Messages (3)
msg99527 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2010-02-18 21:13
This little script 'ctypes-leak.py' leaks memory:

"""
import gc
from ctypes import *

PROTO = WINFUNCTYPE(None)

class Test(object):
    def func(self):
        pass

    def __init__(self):
        self.v = PROTO(self.func)


while 1:
    try:
        Test()
        gc.collect()
    except KeyboardInterrupt:
        print len([x for x in gc.get_objects()
                   if isinstance(x, Test)])
"""

The cause is that patch related to issue #2682; it leaks since rev. 62481 (in trunk) and rev. 62484 (in py3k).

I have not yet been able to find the cause of the leak.
msg99947 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2010-02-23 19:46
CThunkObject is not registered correctly with the cycle GC.  The attached patch, against trunk, fixes the issue.
msg99949 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2010-02-23 20:33
Fixed in rev 78380 (trunk), 78381 (release26-maint), 78382 (py3k), and 78383 (release31-maint).
History
Date User Action Args
2010-02-23 20:33:58thellersetstatus: open -> closed
resolution: fixed
messages: + msg99949
2010-02-23 19:46:08thellersetfiles: + issue7959.patch
keywords: + patch
messages: + msg99947
2010-02-18 21:13:38thellercreate