相关疑难解决方法(0)

静态成员是否会收集垃圾?

静态成员变量是否会被垃圾收集?

例如,让我们使用以下类.

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,bc,以及d垃圾收集时,静态成员是否也shared被收集?可能e会得到一个新的实例shared

c# garbage-collection static-members

44
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

garbage-collection ×1

static-members ×1