Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: Beginner
Jan 1, 2003

Release COM objects immediately

When you use a COM or COM+ from a .NET application and then you set the object reference to Nothing (or let it go out of scope), the object isn't released immediately. The reason: your program communicates with the COM object through a Runtime Callable Wrapper (RCW) object, which is responsible for the real object's lifetime, thus the object will be actually released only when the RCW is garbage collection, which might happen several minutes later or even only when the entire application is shut down.

In most cases this behavior is acceptable, but at times it may be essential that the COM object is explicitly released when the .NET application doesn't need it any longer. You can do this by calling the ReleaseComObject static method of the Marshal class (in the System.Runtime.InteropServices namespace):


' Create the object
Dim obj As New MyComObject()
' Use it
' ....
' Explicitly release it
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap