.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Bugs & Resolutions >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Release COM object

Posted By:Amit Mehra       Posted Date: February 17, 2009    Points: 10    Category: Bugs & Resolutions    URL: http://www.dotnetspark.com  
 

Release COM object Memory is easier in .NET and you can release COM object irrespective the language you are using like C#, VB.Net etc.

.NET framework provide Marshal.ReleaseComObject() method to release COM object reference. it will collect memory allocate by the COM objects.

Lets see an example

This is static method to release COM or activeX object

NOTE: to make use to below function you have to add System.Runtime.InteropServices namespace

C# Code example

//method to release COM object

private static void ReleaseComObject(object activeXObject)

{

if (activeXObject != null)

{

Marshal.ReleaseComObject(activeXObject);

activeXObject = null;

}

}

VB.NET code sample

Private Shared Sub ReleaseComObject(ByVal activeXObject As Object)

If activeXObject IsNot Nothing Then

Marshal.ReleaseComObject(activeXObject)

activeXObject = Nothing

End If

End Sub

Hope this will help developer to release COM or ActiveX object from .NET application.


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend