Releasing COM object (RCW)

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I have a class I am using the RCW on which allows IE to use as an ActiveX
object. The problem is that I holds onto the reference and locks the DLL.
There does not seem to be any way of releasing it when IE is done with it.

My client-side code is trivial:

try
{
obj = new ActiveXObject("Foo.Bar");
obj.DoSomething();
}
catch(e)
{
document.write(e);
}

Is there anyway to get the object released when done so IE does not lock the
DLL?

-- Chris
 
Hello Chris,


Insert a Marshal.ReleaseComObject(obj); after you are done with it.

Please see:
http://samgentile.com/blog/articles/1987.aspx
http://samgentile.com/blog/articles/294.aspx
http://samgentile.com/blog/archive/2003/04/17/5797.aspx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/bridge.asp
http://msdn.microsoft.com/netframew...brary/en-us/dndotnet/html/useframewktools.asp


Sam Gentile
Chief Architect - Adesso Systems
INETA Speaker, Microsoft MVP - .NET/C#
http://samgentile.com/blog/

C> I have a class I am using the RCW on which allows IE to use as an
C> ActiveX object. The problem is that I holds onto the reference and
C> locks the DLL. There does not seem to be any way of releasing it when
C> IE is done with it.
C>
C> My client-side code is trivial:
C>
C> try
C> {
C> obj = new ActiveXObject("Foo.Bar");
C> obj.DoSomething();
C> }
C> catch(e)
C> {
C> document.write(e);
C> }
C> Is there anyway to get the object released when done so IE does not
C> lock the DLL?
C>
 
Back
Top