Solved

How to use Marshal.ReleaseComObject()

Posted on 2004-10-14
23
1,854 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now