Solved

How to use Marshal.ReleaseComObject()

Posted on 2004-10-14
23
1,867 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 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