Click to See Complete Forum and Search --> : Local Remote Reference Counting


M Titchmarsh
April 19th, 1999, 10:12 AM
I have a DCOM issue.
I have a server with a number of objects.
If I call a method of one of the interfaces of these objects and pass an interface pointer to another object (which is also located on the server) then I have a reference counting problem. If I do an AddRef on the interface before passing it, it will increment the local reference count. When the server method has finished it will release the interface that is passed as a parameter but this will decrement the servers reference count. If this function is called enough times the servers reference count will hit zero and the object will be deleted (but the client's reference count for the object will be high). Is there a stylish was of getting round this without calling a special RemoteAddRef() function before passing it. If there is no way round this then it makes a mockery of the DCOM's location transparency claim.

Please help before I end up doing a nasty hack around.

April 19th, 1999, 10:30 AM
I think that this should work - the client should be passing the first object a reference to the client-side proxy for the second object. When the first object calls Release this should go back to the client and update the client's reference count.

Are you saying that it isn't doing this?

M Titchmarsh
April 19th, 1999, 10:45 AM
I am using standard proxy-stub marshalling.
First I create object1 then call an interface method that gets me another interface pointer using ([out] IObject2 **piobj2)
I get an interface to another object (object3) the same way from object1.
I then call piobj3->AddRef(); piobj2->DoSomething(piobj3);
Iobj2::DoSomething releases the interface pointer.

gmadn
April 20th, 1999, 11:56 AM
This example would intentionally get around the reference counting.

In this case when you pass piobj3 to piobj2->DoSomething(piobj3) your are passing a pointer to an object and so would have to AddRef it within DoSomething(). Therefore the release that is called witin DoSomething would correctly decrement the ref count and would not cause the object to be released before time.

Remember the COM specs are just a contract and it is possible to write code that does not comply with the requirements.

I would also advise using smart pointers. This considerably reduces the effors of AddRefing and Releasing interface pointers by encapsulating these ops.

There is the concept of External Connections but I am not aware of a concept of external reference counts.