Barry, I cannot believe someone else (other than me) finally had this
exact same issue (pretty much in the same context too)!

I always assumed it was something else I had done that was responsible
for the memory leak (I had a multi-threaded program with this issue).  

I'm in the process of changing my program to be event-driven
(OnDataChange instead of SyncRead).  This doesn't really solve the
problem, but will hopefully avoid it.

 

Gerrat.

________________________________

 

I have run across what I believe may be a shortcoming with win32com when
trying to call functions that expect one-based indexed arrays as input.
The function I'm trying to invoke which demonstrates the problem is
defined in my documentation as follows: 

HRESULT SyncRead(
      [in] SHORT Source,
      [in] LONG NumItems, 
      [in] SAFEARRAY(LONG) * ServerHandles,
      [out] SAFEARRAY(VARIANT) * Values,
      [out] SAFEARRAY(LONG) * Errors,
      [out,optional] VARIANT * Qualities,
      [out,optional] VARIANT * TimeStamps);

In Python, this looks like:

server_handles = [16384,16385] 
num_items = 2
values, errors, qualities, timestamps = groups.SyncRead(2, num_items,
server_handles)

The num_items parameter is supposed to tell the function the total
number sever_handles being passed in.  Anyway, the above code always
throws a com exception and fails.  I am assuming this issue is due to
the SyncRead function using one-based indexing for its array collection.


However, if I append an extra "dummy" argument to the beginning of the
server_handles list, it will always work.

server_handles = [0, 16384,16385]
num_items = 2
values, errors, qualities, timestamps = groups.SyncRead(2, num_items,
server_handles)

The above example is a very poor solution since it appears to produce a
slow memory leak in my application.  Every 10 to 12 times the SyncRead
call is invoked using the exact same server_handles, memory consumption
increases by 4kb.  This memory leak problem does not happen when called
from VB. 

As an amusing test, I tried setting the variables passed to the function
as follows:

server_handles = [0, 16384, 16385, 0, 0, 0, 0, 0, 0, 0, 0, 0]
num_items = 2

This makes an even bigger memory leak, leading me to believe any extra
elements passed in the list beyond the num_items passed will always be
allocated but never freed. 

Does Mark or anyone else know how to correctly pass a collection to a
COM call using one-based indexing that won't cause a mem leak?   I
couldn't find any mention of this issue in the Python Win32 book other
than an Excel example which didn't seem to apply. 

-BB

_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to