[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MysterX changes exp-tagged



"Michael Sperber [Mr. Preprocessor]" schrieb:
> >>>>> "Paul" == Paul A Steckler <steck@cs.rice.edu> writes:
> 
> Paul> Yes, exposing the reference-counting mechanism
> Paul> at the Scheme level is ugly, but I can't think of a better
> Paul> way to deal with this problem.
> 
> I'm probably being naive, but what about using a finalizer to
> decrement the count?

this is not the problem. of course this is done.

the problem is that "some" COM servers do increment 
the internal m_cRef on CoCreateInstance(),
thus the internal servers and local clients refcounts are not in synch.
However, a QueryInterface() call should increment the server m_cRef through 
the given interface pointer. Some server implementors mix this up.
--
//pIUnknown was obtained through other means.
IProvideClassInfo    *pPCI;
HRESULT               hr;
hr=pIUnknown->QueryInterface(IID_IProvideClassInfo, (void **)&pPCI);
if (SUCCEEDED(hr))    {    
	//Use pCPI to do whatever you want.    
	pCPI->Release();    
} 
else    {    
	//QueryInterface failed; object doesn't support interface.    
}
--
[http://msdn.microsoft.com/library/books/inole/S10fa.htm]

it can happen that the client deletes it but the server still keeps it 
(memory leak. and worse, the server may refuse to shut-down)

and it can happen that the server already deleted it, but the client 
still keeps it. on any next access you might get an access exception or 
something worse (server memory space used by other objects).

"Inside OLE" notes these rules:
--
The concepts governing reference counting can be distilled into two
fundamental rules:

* Creation of a new interface pointer to an object must be followed by an
AddRef call 
through that new pointer.
* Destruction of an interface pointer (such as when the pointer variable goes
out of 
scope in the client) must be preceded by a Release call through that pointer.

Because some objects internally use interface-specific reference counting,
clients 
must always match AddRef and Release calls through each interface pointer.
--
[http://msdn.microsoft.com/library/books/inole/S10f5.htm]

Always doing a AddRef() is much safer. 
The worst problem is a server which will refuse to shutdown. 
(a "hanging excel session"...)
there you can decrement it my hand.
-- 
Reini Urban
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html