Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Releasing COM Objects

$
0
0

Hi,

 

I just started with vb.net and I am not really familiar with releasing COM object yet.

I am using Visual Studio 2015 and my program is for Office 2007 and above.

So I am trying to do it perfect but I am not sure if this is the correct way to release COM objects.

Example:

 [...]

If ActiveWindow IsNot Nothing Then

    Marshal.ReleaseComObject(ActiveWindow.SELECTION.ShapeRange)

    Marshal.ReleaseComObject(ActiveWindow.SELECTION)

    Marshal.ReleaseComObject(ActiveWindow)

    ActiveWindow = Nothing

End If

 [...]

  1. Is it necessary to release each level separately?

Seen here: http://www.codeproject.com/Tips/235230/Proper-Way-of-Releasing-COM-Objects-in-NET

  1. Is it “dangerous” to use more than two dots at a time when working with COM objects (ActiveWindow.SELECTION.ShapeRange) - Or should I assign each level to a seperate variable?

Seen here: http://www.siddharthrout.com/2012/08/06/vb-net-two-dot-rule-when-working-with-office-applications-2/

  1. Is there a way to check at the end of each function – at least in debugging mode – if there is any COM object left behind and not released yet?

Many thanks.


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>