C
cmbardon
I have a C# application that uses a C++ COM exe server, and I've
noticed some strange behaviour with the life cycle of the object. In
my .net app, I create an instance of the COM object (generated RCW),
and am able to deal with methods and connection points without any real
problems. The object is a member variable of the main client form.
When the client application is closed however, the COM server is not
always advised, meaning that the exe server process is not ended. I
was able to rectify this by adding a call to Marshal.ReleaseComObject()
to my code, but now I'm wondering what the issue was in the first
place.
My guess at this point is that for COM objects, the Release() method of
the IUnknown interface is called when the object is deleted by the
garbage collector. For some reason, when my client application exits,
the garbage collector isn't always run on its memory, meaning that the
call to Release() never happens. Is this anywhere even close to
correct? Is there something else that I'm missing? At this point I'm
just trying to understand what's happening rather than just guessing,
and I'm sure someone else here has run into a similar issue.
Thanks!
Chris
noticed some strange behaviour with the life cycle of the object. In
my .net app, I create an instance of the COM object (generated RCW),
and am able to deal with methods and connection points without any real
problems. The object is a member variable of the main client form.
When the client application is closed however, the COM server is not
always advised, meaning that the exe server process is not ended. I
was able to rectify this by adding a call to Marshal.ReleaseComObject()
to my code, but now I'm wondering what the issue was in the first
place.
My guess at this point is that for COM objects, the Release() method of
the IUnknown interface is called when the object is deleted by the
garbage collector. For some reason, when my client application exits,
the garbage collector isn't always run on its memory, meaning that the
call to Release() never happens. Is this anywhere even close to
correct? Is there something else that I'm missing? At this point I'm
just trying to understand what's happening rather than just guessing,
and I'm sure someone else here has run into a similar issue.
Thanks!
Chris