Memory leak problems with python and COM

Etienne Labuschagne etiennel at geospace.co.za
Thu Jul 13 03:57:29 EDT 2000


Hi there,

I have a COM server written in C++ which accepts VARIANTs as input.  The
VARIANT must be a SAFEARRAY of chars (bytes) in which the data is passed.

On the python side, I pass the data to the COM server as follows:

a = array('l')
#add some data to a
b = buffer(a)
CallCOMMethod(b) #passing b to the COM server
del b
del a    #i've tried this both ways around

On the C++ side I get the data as a VARIANT containing a SAFEARRAY. The data
in the SAFEARRAY is of type char* (bytes).  I do this so that I can directly
cast the char* to a structure that is in the correct format wihout having to
copy the values one for one, thus getting some extra speed in using the
data.

Each time I pass an array to the COM server, python's memory usage goes up.
The memory doesn't ever go down even if I kill the COM server.  Passing
enough array's eventually causes the computer to run out of memory.

I have done the following to try and stop the memory leak:

Deleted a and b on the python side and then destroying the COM server - that
doesn't clear up the memory. I am using SafeArrayAccessData and
SafeArrayUnlock on the server side to make sure that it releases the data on
the server side.

Is there something else that I must do?

ANY help would be appreciated!

Regards
Etienne





More information about the Python-list mailing list