Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Release COM objects earlier

Total Hit ( 2933)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


If you're using a COM object through COM Interop you should be aware that the object isn't released as soon as you set it to Nothing, as it happens with VB6. Instead, the object will be released only at the first garbage collections that occurs after the object is set to Nothing or goes out of scope.

If the object's destructor - the Class_Terminate routine in VB jargoon - contains important code that should be executed as soon as the main application doesn't need the object any longer - for example, it closes a file or a database connection - you should force the release of the COM object as soon as you don't need it. You can do this with the Marshal.ReleaseComObject static method. The following examples shows how to do:

Click here to copy the following block
' this is a COM component that does cleanup code when it is destroyed
Dim obj As New MyComLibrary.MyComObject
' use the object
' ...
' force the release of the COM object and set it to Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing

If you 't sure that an object variable points to a COM object, you can use the Marshal.IsComObject shared method before using the ReleaseComObject method: aren
If Marshal.IsComObject(obj) Then
  Marshal.ReleaseComObject(obj)
End If


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.