静态成员变量是否会被垃圾收集?
例如,让我们使用以下类.
public class HasStatic {
private static List<string> shared = new List<string>();
}
Run Code Online (Sandbox Code Playgroud)
并且假设它像这样使用:
//Startup
{
HasStatic a = new HasStatic();
HasStatic b = new HasStatic();
HasStatic c = new HasStatic();
HasStatic d = new HasStatic();
//Something
}
//Other code
//Things deep GC somewhere in here
HasStatic e = new HasStatic();
Run Code Online (Sandbox Code Playgroud)
当a,b和c,以及d垃圾收集时,静态成员是否也shared被收集?可能e会得到一个新的实例shared?