【发布时间】:2016-02-29 01:14:29
【问题描述】:
如果我有类似的东西:
public static class StaticClass
{
public static int x;
public static void Do(int y)
{
x = y;
}
}
你不能实例化StaticClass,那么垃圾收集器什么时候会处理它呢?
它会在执行的应用程序的整个生命周期内保留在内存中吗?
【问题讨论】:
-
它将保留在内存中,直到应用程序关闭。
-
如果您的应用程序是 Asp.net,那么静态变量将在应用程序池回收时重新实例化。否则,它将保留在内存中,直到应用程序重新启动/关闭。
标签: c# .net static garbage-collection static-classes