This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author a01
Recipients a01
Date 2011-09-17.06:29:25
SpamBayes Score 6.694862e-05
Marked as misclassified No
Message-id <1316240966.68.0.395492985431.issue12998@psf.upfronthosting.co.za>
In-reply-to
Content
When using Python 2.5.4 on Windows (and potentially other versions and platforms), usage of CTypes like the following cause a memory leak.  The memory leak can be verified with ProcessExplorer, as the memory Python takes up keeps increasing until eventually Python will get a MemoryError.
----
import ctypes
def hi():
    class c1(ctypes.Structure):
            _fields_=[('f1',ctypes.c_uint8)]
    class c2(ctypes.Structure):
            _fields_=[('g1',c1*2)]

while True:
    test=hi()
----

This is true even if the garbage collector is called explicitly:
----
import gc
import ctypes
def hi():
    class c1(ctypes.Structure):
            _fields_=[('f1',ctypes.c_uint8)]
    class c2(ctypes.Structure):
            _fields_=[('g1',c1*2)]

while True:
    test=hi()
    test2=gc.collect()
----

It is also true if "del" is called on the return value of the function.

In order to get the memory leak, it appears to be necessary to have two Structure classes, with one of them containing a "multiple" of the other one as a field.

In a code project where functions returning Structure classes similarly to this example are being used, MemoryError has been encountered.

See: http://stackoverflow.com/users/553702/user553702
History
Date User Action Args
2011-09-17 06:29:26a01setrecipients: + a01
2011-09-17 06:29:26a01setmessageid: <1316240966.68.0.395492985431.issue12998@psf.upfronthosting.co.za>
2011-09-17 06:29:26a01linkissue12998 messages
2011-09-17 06:29:25a01create