Re: Reference counting and graceful termination of an ATL singleton.
Your reference count is 5 due to a proxy optimization - when
your obect is marshaled after initially created, the proxy grabs
5 references on it right away. This way, if a new proxy needs
to be created at the same client (say in another apartment),
there will be no need to get back to the object's server to
obtain the new reference. When the client releases all of its
references, the proxy releases all 5 references on your object
in one go. In short - never count on your reference count
(pun not intended) to get the actual number of client references
for your object.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
"Sergei V" <sv@a.c.ad.e.m.org> wrote in message
news:ugmZ63vmHHA.4772@TK2MSFTNGP05.phx.gbl...
Hello, the Group.
If for some reason a client of ATL COM-object terminates abnormally
the object will stay in memory until aborted.
(say, this is an out-of-proc singleton)
Is there a way to shut it down gracefully so that it will free resources
it
allocated at creation (in particular, these are hardware resources)?
In other words, is there a function which if called through an interface
will, say, cause reference count go down to zero as if all clients
normally
dereference the COM-object?
Or, at least, is there a way for the client to get the object's reference
count?
I've tried to read m_dwRef variable, but every client receives it equal 5
:-(
Am I doing something wrong?
(everything works: after last client execute ComUninitialize() the
COM-object
gets the FinalRelease() executed and terminates.)
Any suggestions or links to docs are appreciated.
Thank you.