What are alternatives to “free” this object? it normally happens when call the .Exit() method is called, but in this case, I can’t do this because the user that should close the word application instance. I thought to do wordApp = null or call GC.Collect(); what’s the best solution and why? thanks in advance.
I’m using this currently:
public static void Free()
{
if (wordApp != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
GC.Collect();
}
}
The most aggressive way to ensure that the Interop object is properly released is the using the double
Collect–WaitForPendingFinalizerspattern, adapted from Releasing COM Objects: