我有以下代码,我想知道是否需要手动释放ComObject
,否则垃圾收集器会为我发布它?
wordApp = new Word.Application();
wordDoc = new Word.Document();
// some stuff
wordDoc.Close(null, null , null);
wordApp.Quit();
if(System.Runtime.InteropServices.Marshal.IsComObject(wordDoc))
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc);
wordDoc = null;
if (System.Runtime.InteropServices.Marshal.IsComObject(wordApp))
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
wordApp = null;
上述代码是否正确或最终我不应该使用Marshal.IsComObject
?