Releasing COM-Object not necessary?

61 Views Asked by At

So with _excel = New Excel.Application if im not using _excel.Quit and FinalReleaseComObject(_excel), when my application closes, the excel process will close too.

On the other hand when I use both cleanup methods, excel process will stay until my application closes.

Im using Windows 10 and Visual Studio 22

So has cleaning up unmanaged ressources become out of date?

1

There are 1 best solutions below

1
Drunken Code Monkey On

The Office COM interops are being notoriously bad here... Normally what you should be doing is dispose of every object in the inverse order that they were created. For example, first you create Excel.Application, but then I imagine you also have references to workbooks and sheets. If you call .Quit before you first dispose references to the worksheets and close the workbook, the process stays in memory. You shouldn't have to call FinalReleaseComObject, in fact if you still have references not disposed, it may or may not crash the process...