Solved

How to use Marshal.ReleaseComObject()

Posted on 2004-10-14
23
1,871 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

719 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