Why do I have to call del explicitly for com objects?

bg_ie at yahoo.com bg_ie at yahoo.com
Fri Jan 19 07:42:58 EST 2007


Hi,

I'm creating objects in my python script belonging to a COM object
which I dispatch using win32com.client.DispatchEx. Hence, dllhost.dll
is the concerned process. The problem is that the objects destructor
within the com object is not called if the object lives past a certain
number of seconds. For example, this function will not call the
destructor concerned with obj unless the sleep is commented out.

def fnction:
  obj = comobj.createACertainObject()
  obj.doStuff()
  sleep(10)
  obj.doMoreStuff()
  #del obj

It seems to me that the GC forgets about obj after a certain amount of
time. I can force the destructor to be called using del obj at the end
of my function, but why do I have to call this explicitly?

Thanks for your help,

Barry.




More information about the Python-list mailing list