How to use Marshal.ReleaseComObject()

Hi friends

Can anyone explain how the ReleaseComObject fnction works with a simple sample.

how use the ReleaseComObject to release the  AxWebBrowser object ??

Rehgards
Prakash
LVL 10
prakash_prkAsked:
Who is Participating?
 
Mikal613Commented:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesmarshalclassreleasecomobjecttopic.asp

obj = CreateObject("Com", "excel.application.9")
   //code that uses the object goes here
   
   ReleaseObject(obj)
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
iboutchkineConnect With a Mentor Commented:
You can prevent com object hanging around by explicitly cleaning up any com
objects you instantiated with Marshal.ReleaseComObject and then invoking the
..NET garbage collecter before exiting.

Example for Excel
Something like:

While (Marshal.ReleaseComObject(m_excelObj) <> 0) ' Repeat until no more COM references
End While

or  
        Do While System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
        Loop
0
 
prakash_prkAuthor Commented:
Sorry Friends.
I am very busy in last four days. So that only i ddn't perticipate.


I put the webbrowser control to my form via a the windows form desginesr
It creates the object like in the following syntax

AxWebBroswer1 = new AxWebBrowser();

How do i use the Release COM object for this

Regards
Prakash

0
 
Mikal613Commented:
ReleaseObject(AxWebBroswer1 )
0
 
Mikal613Commented:
sorry ;


ReleaseComObject(AxWebBroswer1 )
0
 
prakash_prkAuthor Commented:
Dear  Milka613
I use the following stmt .

System.Runtime.InteropServices.Marshal.ReleaseComObject(Me.AxWebBrowser1)

But it throws InvalidCastException

Regards
Prakash
0
 
prakash_prkAuthor Commented:
Where I can found ReleaseObject() function?

Can you give the namespace which it resides

Regards
Prakash

0
 
Mikal613Commented:
System.Threading
0
 
Mikal613Commented:
or System.ServiceProcess
0
 
Mikal613Commented:
if that doesnt work then do
AxWebBroswer1.dispose or

AxWebBroswer1  = nothing
0
 
prakash_prkAuthor Commented:
I didn't able to find the function ReleaseObject in Either System.Threading nor System.ServiceProcess
0
 
Bob LearnedCommented:
The AxWebBrowser is not a COM object, it is a .NET wrapper for the WebBrowser control.

Bob
0
 
prakash_prkAuthor Commented:

Ok

How do i release teh memory obtained by  AxWebBrowser object
Prakash
0
 
Mikal613Commented:
AxWebBroswer1.dispose or

AxWebBroswer1  = nothing
0
 
prakash_prkAuthor Commented:

I tried it already Mikal613 . but it doesn't release the memory space .still My application eats 220 MB Memory
0
 
Mikal613Commented:
try
Marshal.Release(AxWebBroswer1)
0
 
Mikal613Commented:
While (Marshal.Release(AxWebBroswer1))
End While
0
 
Mikal613Commented:
While (Marshal.Release(AxWebBroswer1)<> 0)
End While

Sorry!!
0
 
Mikal613Commented:
Check This out!!!

There is  bug in the axWebBrowser  and a fix

http://www.developersdex.com/csharp/message.asp?p=1111&r=4616047&page=2

Read the whole thing
0
 
prakash_prkAuthor Commented:
Thank you for all the tips

I navigate the axwebbrowser to about:blank before destroy it
And I call the destroy method for all the controls in the form

some amount o fmemory is released

Thanks for all the help

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.