Message144170
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 |
|
Date |
User |
Action |
Args |
2011-09-17 06:29:26 | a01 | set | recipients:
+ a01 |
2011-09-17 06:29:26 | a01 | set | messageid: <1316240966.68.0.395492985431.issue12998@psf.upfronthosting.co.za> |
2011-09-17 06:29:26 | a01 | link | issue12998 messages |
2011-09-17 06:29:25 | a01 | create | |
|