<small id='NbgFg'></small><noframes id='NbgFg'>

  • <legend id='NbgFg'><style id='NbgFg'><dir id='NbgFg'><q id='NbgFg'></q></dir></style></legend>

        <bdo id='NbgFg'></bdo><ul id='NbgFg'></ul>
        <i id='NbgFg'><tr id='NbgFg'><dt id='NbgFg'><q id='NbgFg'><span id='NbgFg'><b id='NbgFg'><form id='NbgFg'><ins id='NbgFg'></ins><ul id='NbgFg'></ul><sub id='NbgFg'></sub></form><legend id='NbgFg'></legend><bdo id='NbgFg'><pre id='NbgFg'><center id='NbgFg'></center></pre></bdo></b><th id='NbgFg'></th></span></q></dt></tr></i><div id='NbgFg'><tfoot id='NbgFg'></tfoot><dl id='NbgFg'><fieldset id='NbgFg'></fieldset></dl></div>

      1. <tfoot id='NbgFg'></tfoot>
      2. 静态成员是否曾经被垃圾收集?

        Do static members ever get garbage collected?(静态成员是否曾经被垃圾收集?)
          <tbody id='qZCvV'></tbody>
          • <small id='qZCvV'></small><noframes id='qZCvV'>

            <legend id='qZCvV'><style id='qZCvV'><dir id='qZCvV'><q id='qZCvV'></q></dir></style></legend>

            <tfoot id='qZCvV'></tfoot>

                <i id='qZCvV'><tr id='qZCvV'><dt id='qZCvV'><q id='qZCvV'><span id='qZCvV'><b id='qZCvV'><form id='qZCvV'><ins id='qZCvV'></ins><ul id='qZCvV'></ul><sub id='qZCvV'></sub></form><legend id='qZCvV'></legend><bdo id='qZCvV'><pre id='qZCvV'><center id='qZCvV'></center></pre></bdo></b><th id='qZCvV'></th></span></q></dt></tr></i><div id='qZCvV'><tfoot id='qZCvV'></tfoot><dl id='qZCvV'><fieldset id='qZCvV'></fieldset></dl></div>
                  <bdo id='qZCvV'></bdo><ul id='qZCvV'></ul>
                • 本文介绍了静态成员是否曾经被垃圾收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  静态成员变量会被垃圾回收吗?

                  Do static member variables ever get garbage collected?

                  例如,让我们使用下面的类.

                  For example, let's use the following class.

                  public class HasStatic {
                      private static List<string> shared = new List<string>();
                  
                  }
                  

                  假设它是这样使用的:

                  //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();
                  

                  abcd 被垃圾回收时,静态成员 共享 也被收集?e 是否有可能获得 shared 的新实例?

                  When a, b, c, and d are garbage collected does the static member shared get collected as well? Could e possibly get a new instance of shared?

                  推荐答案

                  不,静态成员与 Type 相关联,Type 与加载它的 AppDomain 相关联.

                  No, static members are associated with the Type, which is associated with the AppDomain it's loaded in.

                  请注意,对于要初始化的类和 shared 变量,不必有 任何HasStatic 实例引用 List<string>.

                  Note that there doesn't have to be any instances of HasStatic for the class to be initialized and the shared variable to have a reference to a List<string>.

                  除非您考虑卸载 AppDomain 的情况,否则静态变量可以永远被视为 GC 根.(当然,如果改变了 HasStatic.shared 的值以引用不同的实例,第一个实例可能符合垃圾回收的条件.)

                  Unless you're considering situations where AppDomains get unloaded, static variables can be regarded as GC roots forever. (Of course, if something changes the value of HasStatic.shared to reference a different instance, the first instance may become eligible for garbage collection.)

                  这篇关于静态成员是否曾经被垃圾收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                • <i id='hLu9H'><tr id='hLu9H'><dt id='hLu9H'><q id='hLu9H'><span id='hLu9H'><b id='hLu9H'><form id='hLu9H'><ins id='hLu9H'></ins><ul id='hLu9H'></ul><sub id='hLu9H'></sub></form><legend id='hLu9H'></legend><bdo id='hLu9H'><pre id='hLu9H'><center id='hLu9H'></center></pre></bdo></b><th id='hLu9H'></th></span></q></dt></tr></i><div id='hLu9H'><tfoot id='hLu9H'></tfoot><dl id='hLu9H'><fieldset id='hLu9H'></fieldset></dl></div>
                  • <small id='hLu9H'></small><noframes id='hLu9H'>

                    <legend id='hLu9H'><style id='hLu9H'><dir id='hLu9H'><q id='hLu9H'></q></dir></style></legend>

                      <tbody id='hLu9H'></tbody>

                          • <bdo id='hLu9H'></bdo><ul id='hLu9H'></ul>
                            <tfoot id='hLu9H'></tfoot>