Solved

How to use Marshal.ReleaseComObject()

Posted on 2004-10-14
23
1,869 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
23 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 48

Expert Comment

by:Mikal613
ID: 12309790
0
 
LVL 28

Assisted Solution

by:iboutchkine
iboutchkine earned 100 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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 400 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

713 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