[python-win32] Matlab COM object cause memory leak
Thomas Lidebrandt
thomas.lidebrandt at gmail.com
Mon Jul 14 14:00:45 CEST 2008
Hello I have a Server application that uses Matlab, this works fine when I
use the Execute method to evaluate and retrieve data. However, using the
method GetFullMatrix in the method getvar seems to cause a memory leak.
Anyone got any idea?
I use the following code for the communication with Matlab
import pythoncom, pywintypes
from win32com.client import Dispatch
class MatlabServer():
def __init__(self):
pythoncom.CoInitialize()
matlab_object = Dispatch('matlab.application.single')
self.execute = getattr(matlab_object, 'Execute')
self.putfullmatrix = getattr(matlab_object, 'PutFullMatrix')
self.getfullmatrix = getattr(matlab_object, 'GetFullMatrix')
self.getchararray = getattr(matlab_object, 'GetCharArray')
def __del__(self):
pythoncom.CoUninitialize()
def setvar(self, xnam, x, workspace = "base"):
if type(x) is not list:
x = [ x ]
self.putfullmatrix(xnam, workspace, x, None)
def getvar(self, xnam, workspace = "base"):
try:
return self.getfullmatrix(xnam, workspace, None, None)[0]
except pywintypes.com_error:
return []
def getstring(self, xnam, workspace = "base"):
try:
return self.getchararray(xnam, workspace)
except pywintypes.com_error:
return ''
/Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20080714/5e8430dd/attachment.htm>
More information about the python-win32
mailing list