【发布时间】:2012-06-13 09:14:35
【问题描述】:
“释放”这个对象的替代方法是什么?它通常在调用.Exit() 方法时发生,但在这种情况下,我不能这样做,因为用户应该关闭单词应用程序实例。我想做wordApp = null 或致电GC.Collect(); 什么是最好的解决方案,为什么?提前致谢。
我目前正在使用这个:
public static void Free()
{
if (wordApp != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
GC.Collect();
}
}
【问题讨论】:
-
设置为空。执行 marshal.releasecomobject 并调用 GC.collect
标签: c# memory-management garbage-collection