?
Solved

How to use Marshal.ReleaseComObject()

Posted on 2004-10-14
23
Medium Priority
?
1,878 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:prakash_prk
22 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 12309762
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
 
LVL 28

Assisted Solution

by:iboutchkine
iboutchkine earned 300 total points
ID: 12310831
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
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
LVL 10

Author Comment

by:prakash_prk
ID: 12344480
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
 
LVL 48

Expert Comment

by:Mikal613
ID: 12344487
ReleaseObject(AxWebBroswer1 )
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12344493
sorry ;


ReleaseComObject(AxWebBroswer1 )
0
 
LVL 10

Author Comment

by:prakash_prk
ID: 12344531
Dear  Milka613
I use the following stmt .

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

But it throws InvalidCastException

Regards
Prakash
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 1200 total points
ID: 12344543
0
 
LVL 10

Author Comment

by:prakash_prk
ID: 12344581
Where I can found ReleaseObject() function?

Can you give the namespace which it resides

Regards
Prakash

0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12344592
System.Threading
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12344602
or System.ServiceProcess
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12344663
if that doesnt work then do
AxWebBroswer1.dispose or

AxWebBroswer1  = nothing
0
 
LVL 10

Author Comment

by:prakash_prk
ID: 12344699
I didn't able to find the function ReleaseObject in Either System.Threading nor System.ServiceProcess
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12346248
The AxWebBrowser is not a COM object, it is a .NET wrapper for the WebBrowser control.

Bob
0
 
LVL 10

Author Comment

by:prakash_prk
ID: 12370017

Ok

How do i release teh memory obtained by  AxWebBrowser object
Prakash
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12370152
AxWebBroswer1.dispose or

AxWebBroswer1  = nothing
0
 
LVL 10

Author Comment

by:prakash_prk
ID: 12370194

I tried it already Mikal613 . but it doesn't release the memory space .still My application eats 220 MB Memory
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12370255
try
Marshal.Release(AxWebBroswer1)
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12370271
While (Marshal.Release(AxWebBroswer1))
End While
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12370279
While (Marshal.Release(AxWebBroswer1)<> 0)
End While

Sorry!!
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12370315
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
 
LVL 10

Author Comment

by:prakash_prk
ID: 12482824
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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question