This code shouldn't be causing any leaks in itself.
In general, the RCW does AddRef during its construction, and the Release is
called during finalization. No AddRef is performed by .NET when you call
methodCall. You shouldn't even need to call Marshal.FinalReleaseComObject
because when the garbage collector collects your RCWs the underlying COM
references will be released.
Now, if your implementation wrapper.methodCall performs AddRef, then that
may be where you are leaking. Circular references in COM are known to be an
issue. Are the COM classes yours or are they third party?
Adam
[quoted text, click to view] "Nishith Prabhakar" wrote:
> Hi,
>
> I am facing some memory leak problems with COM interop cleanup. Will
> the following code cause any memory leaks because of the
> wrapper.methodCall method (part of the exposed COM interface).
>
> 1) Is the refcount incremented when the methodCall is made?
> 2) If yes, where is the refcount - in "wrapper" or in "otherWrapper"
> 3) How should the reference created by the methodCall( ) be
> decremented?
>
> Regards
> Nishith
>
> MyFirstComRCWWrapper wrapper = new MyFirstComRCWWrapper();
>
> MyOtherRCWWrapper otherWrapper = new MyOtherRCWWrapper();
>
> int result = wrapper.methodCall(otherWrapper); // Will this cause a
> memory leak?
>
> Marshal.FinalReleaseComObject(otherWrapper);
> otherWrapper = null;
>
> // Release on other wrapper
> Marshal.FinalReleaseComObject(wrapper);
> wrapper = null;