如果一个静态类有任何IDisposable静态变量,那么该类是否需要有一个"静态析构函数"来处理这些变量呢?例如:
public static StaticClass
{
static SomeDisposableType
someDisposable = new SomeDisposableType();
static readonly StaticDestructor
staticDestructor = new StaticDestructor();
private sealed class StaticDestructor
{
~StaticDestructor()
{
someDisposable.Dispose();
}
}
}
Dispose
- http://joeduffyblog.com/2005/04/08/dg-update-dispose-finalization-and-resource-management/ / https://devblogs.microsoft.com/cbrumme/finalization/ 。即使如此 - 什么时候是调用终结器的正确时间呢? - mjwills