Re: Asynchronouse Pluggable Protocols... not relasing COM object




Bilz wrote:
All,

I have implemented Asynchronous Pluggable Protocols with C# in .NET.
Everything is working really well, except that the consumer of my COM
objects is not releasing the object.

Basically, I created a class, ImageProtocol that implements
IInternetProtocolRoot, IInternetProtocolInfo, IInternetProtocol and
IDisposable.

I have a factory class, ImageProtocolFactory that implements
IClassFactory, which creates the ImageProtocol objects. It does it
like this:

public void CreateInstance(IntPtr outer, ref Guid riid, out IntPtr obj)
{
// housekeeping
ImageProtocol protocol = new ImageProtocol();
obj = Marshal.GetComInterfaceForObject(protocol,
typeof(IInternetProtocolInfo));
// more housekeeping
}

After the whole process has unrolled the way the APP doc states it
should, I am left with ImageProtocol objects rooted somewhere out of my
control. I have confirmed this by running the app through a memory
profiler. If 400 objects are created, 400 objects are not disposed.

Any ideas?


OK, I found it! When my IInternetProtocolRoot.Start method was called,
I save off a reference to IInternetProtocolSink, so I can use it later.
If on IInternetProtocolRoot.Terminate, I remove a reference to that
sink, then my objects get cleaned up.

Now, I can't exactly explain why this happened. I would have thought
that if the only thing that is rooting my object is an object that I
have a reference to, then I would have had a circular reference, and
the garbage collector would have taken care of it... but we are talking
about COM here, and I can't say I understand all the voodoo.

B

.