CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    3

    Local Remote Reference Counting

    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.


  2. #2
    Guest

    Re: Local Remote Reference Counting

    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?


  3. #3
    Join Date
    Apr 1999
    Posts
    3

    Re: Local Remote Reference Counting

    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:oSomething releases the interface pointer.




  4. #4
    Join Date
    Apr 1999
    Posts
    5

    Re: Local Remote Reference Counting

    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.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured