Hi All,

I have a Inproc COM-server called by a .Net client.
While tracing my addref/release calls I noticed some strange behaviour.

The COM server with treadingmodel "both" has the following (simplified)IDL
    interface INetTestB : IDispatch
    {
        STDM Doit (void);
    };

    interface INetTestA : IDispatch
    {
        STDM Doit ([in]INetTestB *a);
    };

    coclass NetTestA
    {
        [default] interface INetTestA;
    };
    coclass NetTestB
    {
        [default] interface INetTestB;
    };

I use following code in the dotnet client:

         NetTestB b = new NetTestBClass();
         NetTestA a = new NetTestAClass();

         //X
         a.Doit(b);
         //Y
         a.Doit(b);
         //Z

Before X the is a heavy comunication with QI's addrefs, etc, which is
understandable I thing.
But between X and Y there is also excessive use of COM-functions:

 Addref NetTestB0.2.2.344 (03E12738): 4(glob), 2
 QueryInt NetTestB0.2.2.344 (03E12738): iid=INetTestB
 Addref NetTestB0.2.2.344 (03E12738): 4(glob), 3
 QueryInt NetTestB0.2.2.344 (03E12738): ptr=03E12708, ret=0
 Release NetTestB0.2.2.344 (03E12738): 4(glob), 2
 Addref NetTestB0.2.2.344 (03E12738): 4(glob), 3
 Addref NetTestA0.2.2.344 (03E12818): 4(glob), 2
 QueryInt NetTestA0.2.2.344 (03E12818): iid=INetTestA
 Addref NetTestA0.2.2.344 (03E12818): 4(glob), 3
 QueryInt NetTestA0.2.2.344 (03E12818): ptr=03E127E8, ret=0
 Release NetTestA0.2.2.344 (03E12818): 4(glob), 2
 Addref NetTestA0.2.2.344 (03E12818): 4(glob), 3
 --> COMSERVER-code NetTestA::Doit: this=03E127E8, parm=03E12708
 --> COMSERVER-code NetTestB::Doit: this=03E12708
 Release NetTestB0.2.2.344 (03E12738): 4(glob), 2
 Release NetTestA0.2.2.344 (03E12818): 4(glob), 2


Between Y and Z the addrefs/releases are a bit relaxed, but still,
unnescessary addrefs/releases occurr:

 Addref NetTestB0.2.2.344 (03E12738): 4(glob), 3
 Addref NetTestA0.2.2.344 (03E12818): 4(glob), 3
 --> COMSERVER-code NetTestA::Doit: this=03E127E8, parm=03E12708
 --> COMSERVER-code NetTestB::Doit: this=03E12708
 Release NetTestB0.2.2.344 (03E12738): 4(glob), 2
 Release NetTestA0.2.2.344 (03E12818): 4(glob), 2

Seems to me that the code between X and Y checks how the interfaces should
be marshalled, but the way they do it is not very cheap. Anyway, I don't
understand the addref/release between Y and Z at all.

My questions:
1) Why are the addref/release done each call?
2) How can I get rid of them

Any comments? Or pointers to documentation?

Thanx,
Peter

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to