Destroy a COM reference

  • Thread starter Thread starter Lou
  • Start date Start date
L

Lou

I have a COM object:
ComObject myObj = new ComObject;
This object starts another application.

At some point I want to destroy this immediately so the application it
started closes.
How Do I do this.
In VB it is
ComObject = Nothing;

I tried ComObject = null;
but that did not release the reference and the app it started stayed open?


-Lou
 
I have a COM object:
ComObject myObj = new ComObject;
This object starts another application.

At some point I want to destroy this immediately so the application it
started closes.
How Do I do this.
In VB it is
ComObject = Nothing;

I tried ComObject = null;
but that did not release the reference and the app it started stayed open?

This "released" the .NET reference to the Runtime Callable Wrapper for
the COM object, but the wrapper itself is still there until the GC
collects it. You can use Marshal.FinalReleaseComObject to explicitly
dispose the RCW.
 
Can you explain how I would go about using this method???


I have a COM object:
ComObject myObj = new ComObject;
This object starts another application.

At some point I want to destroy this immediately so the application it
started closes.
How Do I do this.
In VB it is
ComObject = Nothing;

I tried ComObject = null;
but that did not release the reference and the app it started stayed open?

This "released" the .NET reference to the Runtime Callable Wrapper for
the COM object, but the wrapper itself is still there until the GC
collects it. You can use Marshal.FinalReleaseComObject to explicitly
dispose the RCW.
 
Pavel Minaev said:
Can you explain how I would go about using this method???

Marshal.FinalReleaseComObject(myComObject);
myComObject = null;

Oh, and by the way:

A: Because it messes up the order in which people normally read
text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
 
Back
Top